php cURL class

This is an easy to use PHP/cURL class to handle most needed tasks


Table of Contents

Installation
To download file
Post Form
GET form
Retrieve Header
basic authentication
Returned Data
Options
Download

How to examples

Installation

To utilize this class, first import curl.class.php into your project, and require it.

Download file

Post Form

so the $data_array key is the form field name and array value is set to the field value. For examples. $data_array[‘zipcode’] = ‘52415’; . [‘zipcode’]=> form field name ‘52415’=> form field value . data_array

Retrieve Header

in this case the request method is HEAD and no body is returned

Get form

Submits a form with the GET method

Basic authentication

To login using basic authentication

Returned Data

All of these examples will return 3 results

1- Contents of the fetched file
2- Get information regarding a specific transfer

it returns a lot of useful information as an associative array

3- return the last error generated by cURL

Options

change agent name

the agent name to use instead of the default ( the default is set to Firefox )

Time out

how long to wait for a response from a server instead of the default ( the default is 25 seconds )

Cookie location

Location of your cookie file instead of the default
( the default is cookie.txt ) to the script home directory )

the path you specify must be relative for example if you have a folder named tmp and want the cookie to saved to this folder it will be like that
example

referer

the referer to use instead of the default (the default is https://www.google.com)

Include header

to include response header with the body

Verbose

To enable verbose which will write more details about the transfer

To change the location of your Verbose file (the default is verbose.txt resides in the script home directory)
the path you specify must be relative for example
if you have a folder named tmp and want the verbose file to saved to this folder it will be like that
example

Redirection limits

To change the max redirections (the default is 4)

An array of HTTP header fields to set

example

Note that it expects to receive data in an array

Download

to download from github

Leave a Reply

Your email address will not be published. Required fields are marked *