Page 1 of 1

cURL Web proxy Script Showing Weird Arrays!

Posted: Fri Jun 16, 2017 9:00 am
by UniqueIdeaMan
Hi,

This is a basic cURL web proxy script.
Why is it showing weird array pattern looking errors ?

Code: Select all


<?php

function CURLGetURL($url){

// use CURL to make request

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url); // the url to retrieve
curl_setopt($ch, CURLOPT_HEADER, 1); // return the header along with body
curl_setopt($ch, CURLOPT_MAXREDIRS, 3); // follow this amount of redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,5); // follow redirects - change or paramterize
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return output as string
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //ignore issues with SSL certificates
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); // connection timeout in seconds
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4"); // the useragent to connect with

// get response and set array up

$urlinfo["html"] = curl_exec($ch);
$urlinfo["status"] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$urlinfo["error"] = curl_error($ch);
$urlinfo["headers"] = curl_getinfo($ch);

curl_close($ch);

// return hash table of response
return $urlinfo;
}

// example
$http = CURLGetURL("http://www.ebay.com");

if($http){

if($http["status"] == 200){

// we got a valid 200 OK response - output html
echo $http["html"];

}else{

// show error
echo "returned a " . $http["status"] . " status error";

// output error details
print_r( $http["error"] );

// output all header info
print_r( $http["headers"] );

}
}
?> 


I get this error:

returned a 403 status errorArray ( [url] => http://www.ebay.com/ [content_type] => text/html [http_code] => 403 [header_size] => 208 [request_size] => 181 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.672 [namelookup_time] => 0.266 [connect_time] => 0.453 [pretransfer_time] => 0.453 [size_upload] => 0 [size_download] => 261 [speed_download] => 388 [speed_upload] => 0 [download_content_length] => 261 [upload_content_length] => -1 [starttransfer_time] => 0.672 [redirect_time] => 0 [redirect_url] => [primary_ip] => 23.42.49.103 [certinfo] => Array ( ) [primary_port] => 80 [local_ip] => 10.2.3.100 [local_port] => 51660 )

Re: cURL Web proxy Script Showing Weird Arrays!

Posted: Fri Jun 16, 2017 7:10 pm
by Christopher
What do you mean why? It is showing exactly what you are echoing:

Code: Select all

// show error
echo "returned a " . $http["status"] . " status error";

// output error details
print_r( $http["error"] );

// output all header info
print_r( $http["headers"] );