我使用PHP curl登录网站,我的代码如下:
<?php
$Luser = "";
$Lpass = "";
if(isset($_POST['username']) && isset($_POST['password']))
{
$Luser = $_POST['username'];
$Lpass = $_POST['password'];
$L_info="http://registration.zwinky.com/registration/loginAjax.jhtmlusername=".$Luser."&password=".$Lpass;
$zwinky_login_file = file_get_contents($L_info, true);
if (substr($zwinky_login_file, 12, 1) == "u"){ $message = "Blank username!"; }
if (substr($zwinky_login_file, 12, 1) == "p"){ $message = "Blank password!"; }
if (substr($zwinky_login_file, 12, 1) == "w"){ $message = "Wrong user/pass combination!"; }
if (substr($zwinky_login_file, 12, 1) == "s"){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $L_info);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "sessions/".$Luser);
curl_setopt($ch, CURLOPT_COOKIEJAR, "sessions/".$Luser);
$response = curl_exec($ch);
curl_close($ch);
$_SESSION['username'] = $Luser;
$_SESSION['password'] = $Lpass;
header('Location: http://idane.me/start.html');
}
echo($message);
}
?>
但我得到一个错误:
警告:无法修改标头信息 - 已经发送的标头(/customers/2/9/0/idane.me/httpd.www/login.php:49上的输出)/ customers / 2/9/0第73行的/idane.me/httpd.www/login.php
第73行:
header('Location: http://idane.me/start.html');
有什么不对吗?
答案 0 :(得分:1)
第49行怎么样?
你应该在标题之后添加exit():
header('Location: http://idane.me/start.html');
exit();