weixin_33674437 2016-09-27 16:06 采纳率: 0%
浏览 31

curl远程登录错误

Curl code:

$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 code:

$.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 code is working fine and on success it logins and redirect to dashboard.But i want to do using curl.What is wrong with my curl code?

  • 写回答

1条回答 默认 最新

  • 7*4 2016-09-27 16:34
    关注

    U use two times CURLOPT_URL and the last one is used.

    So you are sending to http://localhost/hrm_1.7/source/admin/dashboard

    评论

报告相同问题?