我必须在新服务器中遇到会话问题。
会话无法正常使用this link
我已刷新页面不显示会话,然后再次使用 Ctrl + f5 刷新页面,然后显示会话。
请告诉我这是服务器问题或编码问题?
有一个编码问题而不是解决任何问题。
访问链接以查看phpinfo():http://brahmanparivar.com/phpinfo.php
index.php和display.php
<?php session_start(); ?>
<html>
<head>
<title>PHP session</title>
</head>
<body>
<? if(isset( $_SESSION['name'] ) ){
echo $_SESSION['name'];
} else{
echo "not have a Session";
} ?>
<br><br>
<a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
</body>
</html>
logout.php
<?php session_start(); ?>
<html>
<body>
<?php
if(isset( $_SESSION['name'] ) ){
session_destroy();
}else{
echo "not have a Session";
}
?>
<br><br>
<a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
</body></html>
set.php
<?php session_start();
$_SESSION['name']="Session Set"; ?>
<html>
<head>
<title>PHP session</title>
</head>
<body>
<? if(isset( $_SESSION['name'] ) ){
echo "Set a Session :: Session Set";
} ?>
<br><br>
<a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
</body>
</html>
答案 0 :(得分:0)
在logout.php
页面中,您错过了一个php开放标记<?php
。
改变这个:
<? if (isset($_SESSION['name'])) {...
到此:
<?php if (isset($_SESSION['name'])) {...
答案 1 :(得分:0)
我不认为短标签可以解决他的问题。当我运行你的代码时,它完美无缺。 可能是它的配置问题。
请阅读:How to get my session to write to apache
看看是否能解决您的问题,以便进一步解决问题
我想看看phpinfo();
还附上
<?php
session_start();
echo session_id();
?>
到每一页我都不认为你的PHPSESSIONID没有被设置。适当