在發(fā)布之前,我已經(jīng)閱讀了:會話在服務器中不起作用session_start但是,我沒有找到解決問題的方法。好的,我正在編寫一個應用程序,該應用程序使用jQuery AJAX進行用戶登錄頁面,以檢查它們是否被管理,然后將SESSION變量傳遞到頁面中。如果未設置 SESSION,則顯示 403 禁止頁面。admin.php我已經(jīng)在我的機器上運行了代碼,但是,在將所有內容部署到服務器后,它總是顯示 403 禁止。我檢查了 SESSION,發(fā)現(xiàn)它的長度僅為 0;Array()現(xiàn)在我正在嘗試通過以下方式做到這一點:ini_set('session.save_path', $sessdir);
session_start();但我無法讓它在我的本地機器上工作,這里有兩個示例:第一個 PHP 文件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php // abs path of this file function inve(){return "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";} // remove n items from end of a path in string format function rewind_url($dire, $ind){ $pieces = explode('/', $dire); for($i=0; $i<$ind; $i++){ array_pop($pieces); } $pieces = implode('/', $pieces); return $pieces; } function put($str){ print_r("<h2>" . $str . "</h2>"); } $sessdir = rewind_url(inve(), 1); ini_set('session.save_path', $sessdir); session_start(); $_SESSION['name'] = 'joseph'; put($sessdir); put(count($_SESSION)); ?> <a href='another.php'>here</a> </body> </html>第二個 PHP 文件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <?php // abs path of this file function inve(){return "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";} // remove n items from end of a path in string format function rewind_url($dire, $ind){ $pieces = explode('/', $dire); for($i=0; $i<$ind; $i++){ array_pop($pieces); } $pieces = implode('/', $pieces); return $pieces; } function put($str){ print_r("<h2>" . $str . "</h2>"); } $sessdir = rewind_url(inve(), 1); ini_set('session.save_path', $sessdir); session_start(); put(count($_SESSION)); ?> </body> </html>簡而言之,我想在單擊鏈接后看到數(shù)字 1。 我非常感謝您的幫助。
PHP:會話在本地主機但服務器上工作
HUH函數(shù)
2023-10-15 17:18:01