简体   繁体   English

PHP 5.3,URL中的“与”号传递不起作用

[英]PHP 5.3, Ampersand in URL passing not working

I have code that works fine for anything before 5.3, and now this code won't work in php 5.3: 我的代码在5.3之前的任何版本上都可以正常工作,现在此代码在php 5.3中无法正常工作:

    foreach($_GET as $key => $value) { 
    $params .= "&"; 
    $params .= $key."=".$value; 
} 


$fields = array(
    'mode'=>urlencode('native'),
    'cookie_file'=>urlencode($data['cookie_file']),
    'full_status'=>urlencode('1'),
    'remove_cookies'=>urlencode('1'),
    'url'=>urlencode("http://www.domainblocked.com/blocked_name.php?" . $params)
);


//url-ify the data for the POST
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'&');

//open connection
$ch = curl_init();

$get_url = $proxy."?".$fields_string;

print $get_url;
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$get_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//execute post
$html = curl_exec($ch);

The file $proxy refers to a PHP proxy which complains it never gets the $_GET['url'] variable despite the $get_url being: 文件$proxy引用了一个PHP代理,该代理抱怨尽管$get_url是,但它从未获得$_GET['url']变量:

http://www.domainblocked.com/proxy.php?mode=native&cookie_file=%2Ftmp%2FCURLCOOKIEQ1N7ki&full_status=1&remove_cookies=1&url=http%3A%2F%2Fwww.domainblocked.com%2Fblocked_name.php%3F%26room%3D3043542%3B3332215%3B4875165%3B6917670%3B7055833%3B7454057%3B7747396%3B8321764%3B8331103%3B8362498%3B8406246%3B8406305%3B8406671%3B8406728%3B8406965%3B9213754%3B9895515%3B9898865%3B9904319%3B9904558%3B9908327%3B9910403%3B9910760%3B9916830%3B9918045%3B9919351%3B9919603%26avatar69323038%3D%26avatar1%3D6268520%3B6713654%3B7347874%3B7738193%3B7780315%3B8493140%3B8501371%3B8752968%3B9487253%3B9524370%3B9811618%3B10196605%3B10519485%26avatar69527829%3D%26avatar2%3D223055%3B2690693%3B4228334%3B6251471%3B6270797%3B6713654%3B7122151%3B7198849%3B7644202%3B7868916%3B8501371%3B8698810%3B8739013%3B8739767%3B9142768%26avatar38051172%3D%26avatar3%3D4792397%3B6285528%3B7204362%3B7518963%3B7773830%3B7776340%3B8403813%3B8501371%3B9481162%3B9520771%3B9751483%3B9971760%3B9997875%3B10109398%3B10117824%26avatar227598%3D%26avatar4%3D1962690%3B4223019%3B5707484%3B6127072%3B7162053%3B7172244%3B7988191%3B8239420

therefore $_GET['url'] on the proxy file should be http%3A%2F%2Fwww.domainblocked.com%2Fblocked_name.php%3F%26room%3D3043542%3B3332215%3B4875165%3B6917670%3B7055833%3B7454057%3B7747396%3B8321764%3B8331103%3B8362498%3B8406246%3B8406305%3B8406671%3B8406728%3B8406965%3B9213754%3B9895515%3B9898865%3B9904319%3B9904558%3B9908327%3B9910403%3B9910760%3B9916830%3B9918045%3B9919351%3B9919603%26avatar69323038%3D%26avatar1%3D6268520%3B6713654%3B7347874%3B7738193%3B7780315%3B8493140%3B8501371%3B8752968%3B9487253%3B9524370%3B9811618%3B10196605%3B10519485%26avatar69527829%3D%26avatar2%3D223055%3B2690693%3B4228334%3B6251471%3B6270797%3B6713654%3B7122151%3B7198849%3B7644202%3B7868916%3B8501371%3B8698810%3B8739013%3B8739767%3B9142768%26avatar38051172%3D%26avatar3%3D4792397%3B6285528%3B7204362%3B7518963%3B7773830%3B7776340%3B8403813%3B8501371%3B9481162%3B9520771%3B9751483%3B9971760%3B9997875%3B10109398%3B10117824%26avatar227598%3D%26avatar4%3D1962690%3B4223019%3B5707484%3B6127072%3B7162053%3B7172244%3B7988191%3B8239420 因此,代理文件上的$_GET['url']应该是http%3A%2F%2Fwww.domainblocked.com%2Fblocked_name.php%3F%26room%3D3043542%3B3332215%3B4875165%3B6917670%3B7055833%3B7454057%3B7747396%3B8321764%3B8331103%3B8362498%3B8406246%3B8406305%3B8406671%3B8406728%3B8406965%3B9213754%3B9895515%3B9898865%3B9904319%3B9904558%3B9908327%3B9910403%3B9910760%3B9916830%3B9918045%3B9919351%3B9919603%26avatar69323038%3D%26avatar1%3D6268520%3B6713654%3B7347874%3B7738193%3B7780315%3B8493140%3B8501371%3B8752968%3B9487253%3B9524370%3B9811618%3B10196605%3B10519485%26avatar69527829%3D%26avatar2%3D223055%3B2690693%3B4228334%3B6251471%3B6270797%3B6713654%3B7122151%3B7198849%3B7644202%3B7868916%3B8501371%3B8698810%3B8739013%3B8739767%3B9142768%26avatar38051172%3D%26avatar3%3D4792397%3B6285528%3B7204362%3B7518963%3B7773830%3B7776340%3B8403813%3B8501371%3B9481162%3B9520771%3B9751483%3B9971760%3B9997875%3B10109398%3B10117824%26avatar227598%3D%26avatar4%3D1962690%3B4223019%3B5707484%3B6127072%3B7162053%3B7172244%3B7988191%3B8239420 http%3A%2F%2Fwww.domainblocked.com%2Fblocked_name.php%3F%26room%3D3043542%3B3332215%3B4875165%3B6917670%3B7055833%3B7454057%3B7747396%3B8321764%3B8331103%3B8362498%3B8406246%3B8406305%3B8406671%3B8406728%3B8406965%3B9213754%3B9895515%3B9898865%3B9904319%3B9904558%3B9908327%3B9910403%3B9910760%3B9916830%3B9918045%3B9919351%3B9919603%26avatar69323038%3D%26avatar1%3D6268520%3B6713654%3B7347874%3B7738193%3B7780315%3B8493140%3B8501371%3B8752968%3B9487253%3B9524370%3B9811618%3B10196605%3B10519485%26avatar69527829%3D%26avatar2%3D223055%3B2690693%3B4228334%3B6251471%3B6270797%3B6713654%3B7122151%3B7198849%3B7644202%3B7868916%3B8501371%3B8698810%3B8739013%3B8739767%3B9142768%26avatar38051172%3D%26avatar3%3D4792397%3B6285528%3B7204362%3B7518963%3B7773830%3B7776340%3B8403813%3B8501371%3B9481162%3B9520771%3B9751483%3B9971760%3B9997875%3B10109398%3B10117824%26avatar227598%3D%26avatar4%3D1962690%3B4223019%3B5707484%3B6127072%3B7162053%3B7172244%3B7988191%3B8239420

But it never gets it. 但是,它永远不会得到它。

If I dont urlencode the $_GET['url'] then it this: 如果我不对$ _GET ['url']进行urlencode,那么它是这样的:

http://www.domainblocked.com/proxy.php?mode=native&cookie_file=%2Ftmp%2FCURLCOOKIEjtmYSU&full_status=1&remove_cookies=1&url=http://www.domainblocked.com/blocked_name.php?&room=3043542;3332215;4875165;6917670;7055833;7454057;7747396;8321764;8331103;8362498;8406246;8406305;8406671;8406728;8406965;9213754;9895515;9898865;9904319;9904558;9908327;9910403;9910760;9916830;9918045;9919351;9919603&avatar69323038=&avatar1=6268520;6713654;7347874;7738193;7780315;8493140;8501371;8752968;9487253;9524370;9811618;10196605;10519485&avatar69527829=&avatar2=223055;2690693;4228334;6251471;6270797;6713654;7122151;7198849;7644202;7868916;8501371;8698810;8739013;8739767;9142768&avatar38051172=&avatar3=4792397;6285528;7204362;7518963;7773830;7776340;8403813;8501371;9481162;9520771;9751483;9971760;9997875;10109398;10117824&avatar227598=&avatar4=1962690;4223019;5707484;6127072;7162053;7172244;7988191;8239420

Which the proxy receieve $_GET['url'] but it's only http://www.domainblocked.com/blocked_name.php? 哪个代理可以接收到$ _GET ['url']但它只是http://www.domainblocked.com/blocked_name.php?

So I think it has to do with something with the & or urlencode in 5.3 所以我认为这与5.3中的&或urlencode有关

foreach($_GET as $key => $value) { 
    $params .= "&"; 
    $params .= $key."=".$value; 
} 

Switch this (and similar code) with http_build_query() . 使用http_build_query()切换此(和类似的代码http_build_query() It will handle all the encoding. 它将处理所有编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM