2016-09-27 46 views
0

卷曲代码:卷曲远程登录埃罗

$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代码是工作的罚款,并成功登录它并重定向到dashboard.But我想用卷曲的事情。我的卷发代码有什么问题?

+0

是否有管理/仪表板的任何$ _ POST reciver类型的方法? –

+0

@AniruddhaChakraborty,我不知道我的ajax代码正在工作,我需要知道我的卷发代码有什么问题。 – afsarkhan10182

回答

0

U使用两次CURLOPT_URL并使用最后一个。

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

+0

那是因为我不得不重定向到该URL ...就像在Ajax请求中一样,我在成功响应后重定向...最后我只想重定向 – afsarkhan10182

+0

实际上我想远程登录,并且这个crm是基于laravel的。我希望请求所以我把标题(允许起源..)放在laravel的crm中,但是在使用上面的Ajax代码时,我被重定向到了注销页面,但是我的数据没有发布任何跨域错误。请帮帮我。 – afsarkhan10182