1

我相信我的托管公司最近可能会发生一些变化,因为它以前工作过。然而,它们是无用的。

我已经使用file_get_contentswhich 在文件中加载.. 老实说,它是代码包的一部分,我不是 100% 它的作用。但是,url 相当长,它只是简单地回显文件的结果:

IE

$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);

这会产生大约 390 个字符的 URL。如果我将其缩减到大约 360 个字符,它可以正常工作 - 但这不是解决方案,因为我丢失了一些传递到文件中的 GET 数据。

任何想法在我的主机上可能会发生什么变化,现在导致 url 的 360 多个字符引发 403 禁止错误?

我也尝试过 curl 方法 - 它也给出了相同的结果:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cgi);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
4

1 回答 1

2

来自:http ://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.1

服务器应该谨慎对待超过 255 字节的 URI 长度,因为一些较旧的客户端或代理实现可能无法正确支持这些长度。

这意味着您需要避免使用超过 255 的 GET。

正如您所注意到的,某些服务器(您的)不超过 255(在您的情况下为 360)。

使用 POST。

使用卷曲:

$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);

没有卷曲:

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;
}
于 2013-06-18T20:18:11.900 回答