我想登录的大家好,我遇到了问题。条件是Cookie名称不能为空(登录大小写)。这是我的代码
$username = $_POST['email'];
$password = $_POST['pass'];
$ch = curl_init('http://localhost/sid/services/view/Accounts.php');
$jsonData = array( 'USERNAME' => $username, 'PASSWORD' => $password );
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);
$sess_arr = json_decode($result, true);
echo '<pre>';
var_dump($ch);
var_dump($sess_arr);
echo'</pre>';
if(isset($sess_arr['errorMessages'][0])) {
echo $sess_arr['errorMessages'][0];
}
else {
setcookie($sess_arr['ROLE_ID']['ROLE_ID'], $sess_arr['ROLE_ID']['USERNAME'], time() + (86400 * 30), "/");
echo "Login Success!";
}
答案 0 :(得分:0)
setcookie
需要在任何输出(PHP Manual)之前调用。请删除或注释掉以下代码。
echo '<pre>';
var_dump($ch);
var_dump($sess_arr);
echo'</pre>';
此外,就我所看到的var_dump($sess_arr);
输出而言,您可能需要按以下方式更改代码。
foreach ($sess_arr as $sess) {
setcookie($sess['ROLE_ID'], $sess['USERNAME'], time() + (86400 * 30), "/");
}