note 102793 added to function.curl-setopt
| From: | support at lostair dot com | Date: | Mon, 07 Mar 2011 11:26:08 +0000 |
| Subject: | note 102793 added to function.curl-setopt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177607@lists.php.net to get a copy of this message | ||
Force Curl Request To Go To A Particular IP Address
Yes, there is a method of passing an IP address to curl. Excellent for services with multiple IP
addresses and also to take DNS out of the equation for testing/debugging.
function fetch_page($url, $host_ip = NULL)
{
$ch = curl_init();
if (!is_null($host_ip))
{
$urldata = parse_url($url);
// Ensure we have the query too, if there is any...
if (!empty($urldata['query']))
$urldata['path'] .= "?".$urldata['query'];
// Specify the host (name) we want to fetch...
$headers = array("Host: ".$urldata['host']);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// create the connecting url (with the hostname replaced by IP)
$url = $urldata['scheme']."://".$host_ip.$urldata['path'];
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
----
Server IP: 69.147.83.197
Probable Submitter: 188.220.38.106
----
Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php
Edit -- https://master.php.net/note/edit/102793
Del: integrated -- https://master.php.net/note/delete/102793/integrated
Del: useless -- https://master.php.net/note/delete/102793/useless
Del: bad code -- https://master.php.net/note/delete/102793/bad+code
Del: spam -- https://master.php.net/note/delete/102793/spam
Del: non-english -- https://master.php.net/note/delete/102793/non-english
Del: in docs -- https://master.php.net/note/delete/102793/in+docs
Del: other reasons-- https://master.php.net/note/delete/102793
Reject -- https://master.php.net/note/reject/102793
Search -- https://master.php.net/manage/user-notes.php