卷曲代码:
$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。我的卷曲代码有什么问题?