我已经在 PHP 中启动并运行了一个会话,但由于某种原因,有时当我单击一个页面时,会话似乎意外结束。例如:我有一个简单的用户登录页面(只是用户名):INDEX.PHP
<h1>User Sign-In:</h1>
<form name="login" action="main.php" method="post">
Username: <input type="text" name="username">
<input type="submit" value="Submit">
</form>
主.PHP
<?php
session_save_path(trim(`echo ~`).'/php_sessions'); session_start();
$_SESSION['username']= $_POST["username"];
$username = $_SESSION['username'];
if(isset($_SESSION['username']))
{
}
else
header('Location:./index.php');
?>
<body>
<?php
echo "Hello, your username is: " . $_SESSION["username"];
?>
<a href="./main.php">Store</a> | <a href="./basket.php">Basket</a> | <a href="./about.php">About</a> | <a href="./logout.php">Logout</a>
<form name="select1"action="" method="GET">
<select name="higherorlower">
<option value="All">All</option>
<option value="greaterthan">Greater Than</option>
<option value="lowerthan">Lower Than</option>
</select>
Price:<input type="text" name="price"/>
<input type="submit" name="submit" value="Submit" />
篮子.PHP
<?php
session_save_path(trim(`echo ~`).'/php_sessions'); session_start();
$username = $_SESSION['username'];
if(isset($_SESSION['username']))
{
}
else
header('Location:.');
?>
<body>
<?php
echo "Hello, your username is: " . $_SESSION["username"];
?>
<a href="./main.php">Store</a> | <a href="#">Basket</a> | <a href="./about.php">About</a> | <a href="./logout.php">Logout</a>
<h2>
You're currently on the basket page!
</h2>
所以说我输入我的用户名,它把我带到 MAIN.PHP 并很好地显示我的用户名,然后我单击购物篮页面,它也显示我的用户名很好,但是当我从 BASKET.PHP 到 MAIN 时单击。 PHP它丢失了用户名并且什么都不显示......
我不知道发生了什么,任何帮助将不胜感激,谢谢。