[英]PHPSESSID inconsistent via JQuery AJAX Post requests
我有 ReactJS 應用程序,我正在嘗試發送 AJAX 請求以獲取當前的 session 信息。
前端代碼:
$.post('http://localhost/php/user/getSession.php',null,function(data){
console.log(data);
})
getSession.php 代碼:
<?php
session_start();
echo $_SESSION['Username'];
if(!isset($_SESSION['Username'])){
echo "Not set yet";
}
$_SESSION['Username']="ASDASD";
?>
因此,在第一個請求中,我的 output 應該是“尚未設置”,第二個請求應該是“ASDASD”。
當我嘗試直接從谷歌瀏覽器訪問 my.php 文件時,它可以完美運行,並且在每次重新加載頁面時都保持我的 PHPSESSID 相同。 ( http://localhost/php/user/getSession.php ) https://prnt.sc/szjies
當我嘗試通過 AJAX 訪問它時,問題就開始了。 它總是返回:“尚未設置”,並在重定向時創建新的 PHPSESSID(刪除之前保存的任何值)。 My ReactJS app and php backend are in two different folders, because I use XAMPP for Apache and Mysql (don't know if this could be the issue). https://prnt.sc/szjiwz , https://prnt.sc/szjj52
如何確保在創建 ReactJS 應用程序后,我的 PHPSESSID 保持不變(保留我分配給 $_SESSION 的所有值)?
As I know, session will be different at server-side every time refresh or close the page (that mean every access to page, new session will be created every time), I don't think it is possible to keep the session through ajax稱呼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.