Reputation: 359
I believe something with my hosting company may of changed recently as it was previously working. However, they are useless.
I have use file_get_contents
which loads in a file.. to be honest it was part of an code pack that I'm not 100% what it does. However, the url is fairly length, it simply echos out the result of the file:
i.e
$custom = getRealIpAddr()."|||||".$_SESSION['cart']."|||||".makeSafe($_GET['i'])."|||||".$lang;
$pphash = create_paypal_hash(makeSafe($_SESSION['cart']), '', create_password('####'), $custom);
$tosend = base64_encode(urlencode($pphash));
$cgi = "http://www.***********.com/pl/b.pl?a=".$tosend; // TEST LINE
echo file_get_contents($cgi);
This results in a URL of about 390 characters.. if I trim it down to about 360 characters it works fine - however that isn't a solution as I lose some of the GET data passed into the file.
Any ideas what may of changed on my host thats now causing url's over 360 characters to throw a 403 forbidden error?
I've also tried it the curl method - which also gives the same result:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cgi);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Upvotes: 1
Views: 3552
Reputation: 14532
From: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1
Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.
This means you need to avoid using GET longer then 255.
As you have noticed some server (yours) do not go over 255 (360 in your case).
Use POST.
With CURL:
$url = 'http://www.example.com';
$vars = 'var1=' . $var1 . '&var2=' . $var2;
$con = curl_init($url);
curl_setopt($con, CURLOPT_POST, 1);
curl_setopt($con, CURLOPT_POSTFIELDS, $vars);
curl_setopt($con, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($con, CURLOPT_HEADER, 0);
curl_setopt($con, CURLOPT_RETURNTRANSFER, 1);
$re = curl_exec($con);
Without CURL:
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
Upvotes: 2