Javascript Php cURL返回location.replace为相对地址,如何更改?

Javascript Php cURL返回location.replace为相对地址,如何更改?,javascript,php,curl,login,Javascript,Php,Curl,Login,我正在尝试使用cUrl登录网页,代码如下: $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch,

我正在尝试使用cUrl登录网页,代码如下:

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, count($fields)); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$output = curl_exec($ch);
使用浏览器运行脚本将返回404错误,但使用shell运行脚本将返回“location.replace”,其中包含一个相对路径(然后在我的服务器上执行脚本时,将找不到位置)

这就是cUrl返回的结果:

<html>
<head><script>location.replace("main.php?email=xxx%40xxx.xx&lang=it")</script></head>
<body>
<!--pre></pre-->
</body>
</html>

location.replace(“main.php?email=xxx%40xxx.xx&lang=it”)
那么,我可以改变位置吗?我已经尝试将
CURLOPT_FOLLOWLOCATION
切换为false,但没有任何更改

有人能帮我吗


问候语

CURLOPT_FOLLOWLOCATION
只会使curl跟随服务器端的所有重定向。它对响应字符串没有影响

我会让我的登录脚本返回比html/JavaScript重定向更有用的东西。考虑这样做< <
...
$sResponse = curl_exec($rCh);

preg_match('/location.replace\("(.+)"\)/', $sResponse, $aMatch);
header('Location:' . $aMatch[1]);
loginscript.php

$aReturn = array();
$bLoginSuccessfull = true;
if ($bLoginSuccessfull) {
    $aReturn['url'] = 'main.php?email=xxx%40xxx.xx&lang=it';
} else {
    $aReturn['error'] = 'something failed during login process';
}
$aReturn['success'] = $bLoginSuccessfull;

echo json_encode($aReturn);
exit;
还有你的卷发电话

<?php 
$sUrl = 'http://mysite.it/loginscript.php';

$rCh = curl_init();
curl_setopt($rCh, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($rCh, CURLOPT_URL, $sUrl);
curl_setopt($rCh, CURLOPT_POST, count($aFields));
curl_setopt($rCh, CURLOPT_POSTFIELDS, $sFields);
curl_setopt($rCh, CURLOPT_COOKIEFILE, $sCkfile);
curl_setopt($rCh, CURLOPT_HEADER, false);
curl_setopt($rCh, CURLOPT_RETURNTRANSFER, true);
$sResponse = curl_exec($rCh);
curl_close($rCh);

$sResponse = json_decode($sResponse);
if ($sResponse['success']) {
    // Send user to url (main.php?email=xxx%40xxx.xx&lang=it)
    header('Location: ' . $sResponse['url']);
} else {
    echo "Login failed...";
    echo $sResponse['error'];
}

我不明白。如果将
$url
的内容粘贴到浏览器中并按enter键,则不会得到404?不,如果我将$url粘贴到浏览器中,则效果良好