2013-06-18 45 views
1

我相信我的托管公司可能最近更改了它以前的工作。但是,它们是无用的。file_get_contents URL现在太长了

我已经使用加载在文件中的file_get_contents ..说实话,它是代码包的一部分,我不是它的100%。然而,网址是相当长,它只是回声出该文件的结果:

$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禁止的错误?

我也试着它卷曲方法 - 这也给了相同的结果:

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

尝试使用curl扩展? –

+0

问题可能出现在您尝试从服务器加载的服务器上?尝试使用浏览器中的所有参数加载该页面。 – claustrofob

+1

您是连接到您自己的主机还是可能在另一个您尝试访问的网站中进行更改?如果在你自己的盒子上使用'suhosin',你可能想检查'suhosin.get.max_value_length'。 – Wrikken

回答

2

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

服务器应该是谨慎取决于URI长度大于255个字节,因为一些较旧的客户端或代理实现可能不适当地支持这些长度。

这意味着你需要避免使用变长则255

正如您已经注意到了一些服务器(你)不要超过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; 
} 
+0

如何发布到file_get_contents函数? 正如我前面提到的,我不是100%这个文件做什么 - 我所知道的是它需要'a'作为GET。我如何将它转换为POST而不是? – user2183216

+0

如果无法将服务器实现更改为可交换地接受,则无法将GET请求更改为POST请求。它可能工作,如果服务器已经接受它,但更有可能它不会。 – Sven