-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexample.php
More file actions
61 lines (44 loc) · 2.08 KB
/
example.php
File metadata and controls
61 lines (44 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* @version 2.0.x
* @copyright © 2014 Lampix.net
* @author Dragan Dinic <dragan@dinke.net>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require 'vendor/autoload.php';
$curl = new \Dinke\CurlHttpClient;
//pretend to be Firefox 19.0 on Mac
$useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0";
$curl->setUserAgent($useragent);
//uncomment next two lines if you want to automatically manage cookies
//which will store them to file and send them on each http request
//$cookies_file = "/tmp/cookies.txt";
//$curl->storeCookies($cookies_file);
//Uncomment next line if you want to set credentials for basic http_auth
//$curl->setCredentials($username, $password);
//Uncomment next line if you want to set specific referrer
//$curl->setReferer('http://www.foo.com/referer_url/');
//if you want to send some post data
//form post data array like this one
$post_data = ['login' => 'pera', 'password' => 'joe', 'other_foo_field' => 'foo_value'];
//or like a string: $post_data = 'login=pera&password=joe&other_foo_field=foo_value';
//and send request to http://www.foo.com/login.php. Result page is stored in $html_data string
$html_data = $curl->sendPostData("http://www.foo.com/login.php", $post_data);
//You can also fetch data from somewhere using get method!
//Fetch html from url
$html_data = $curl->fetchUrl("http://www.foo.com/foobar.php?login=pera&password=joe&other_foo_field=foo_value");
//if you have more than one IP on your server,
//you can also bind to specific IP address like ...
//$bind_ip = "192.168.0.1";
//$curl->fetchUrl("http://www.foo.com/login.php", $bind_ip);
//$html_data = $curl->sendPostData("http://www.foo.com/login.php", $post_data, $bind_ip);
//and there are many other things you can do like
//use proxy
//$curl->setProxy('http://www.proxyurl.com');
//use proxy auth
//$curl->setProxyAuth('user:pass');
//get http response code for last request
//$http_code = $curl->getHttpResponseCode();
//get last http request duration in sec
//$duration = $curl->getRequestDuration();
?>