在发布之前,我已经阅读了:
但是,我没有找到解决问题的方法。
好的,我正在编写一个应用程序,该应用程序使用jQuery AJAX进行用户登录页面,以检查它们是否被管理,然后将SESSION变量传递到页面中。如果未设置 SESSION,则显示 403 禁止页面。admin.php
我已经在我的机器上运行了代码,但是,在将所有内容部署到服务器后,它总是显示 403 禁止。我检查了 SESSION,发现它的长度仅为 0;Array()
现在我正在尝试通过以下方式做到这一点:
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>
简而言之,我想在单击链接后看到数字 1。 我非常感谢您的帮助。
繁星coding