卷曲远程登录错误

时间:2016-09-27 16:06:26

标签: php ajax curl

卷曲代码:

$username = $_POST["email"];

$password = $_POST["password"];

$headers= array('Accept: application/json','Content-Type: application/json'); 

$url="http://localhost/hrm_1.7/source/admin/login"; 

$data = array('email'=>$username,'password'=>$password);

$postinfo = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS,$postinfo);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);

curl_exec($ch);

curl_setopt($ch, CURLOPT_URL,"http://localhost/hrm_1.7/source/admin/dashboard");

$html = curl_exec($ch);

curl_close($ch);

AJAX代码:

$.ajax({
        type: "POST",
        url: " http://localhost/hrm_1.7/source/admin/login ",
        dataType: 'json',
        data: $('#login-form').serialize()

 }).done( function( response ) {
        if(response.status == "success")
        {
            window.location.href= "http://localhost/hrm_1.7/source/admin/dashboard";
        }

 });

AJAX代码工作正常并且成功登录并重定向到仪表板。但我想使用curl。我的卷曲代码有什么问题?

1 个答案:

答案 0 :(得分:0)

你使用两次CURLOPT_URL,并使用最后一次。

所以你发送到http://localhost/hrm_1.7/source/admin/dashboard