我有兩段代碼,一段是前端網站php代碼,用於呈現前端網頁,另一段代表後端api PHP代碼。在我的前端網站代碼中,我有session_start();session_id()在PHP上不輸出任何內容
我有一塊,一旦用戶登錄,然後我給他或她一個的SessionID做sessionid();
然而,當我使用$sessionid = session_id();
和echo $sessionid
後端API代碼,什麼也沒有輸出。
$user="root";
$password="";
$database="test";
mysql_connect('localhost',$user,$password);
@mysql_select_db($database) or die("Unable to select database");
$username = $first_param;
$username = str_replace("UserName=", "", $username);
$password = $second_param;
$password = str_replace("Password=", "", $password);
$query = "SELECT * FROM `user` WHERE username ='$username' AND password = '$password' ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if (debug) {
echo "<br>";
echo "--------the num of login is ----" .$num;
}
if ($num <1) {
}
else {
$sesid=session_id();
if (debug) {
echo "<br>";
echo "-----login sessionid is------" .$sesid;
echo "<br>";
}
$query = "UPDATE `user` SET sessionid='$sesid' WHERE username ='$username' AND password = '$password'";
mysql_query($query);
}
你的session_start()在哪裏? –