我正在尝试跨目录保存PHP会话数据。这段代码对我不起作用,我需要它重定向到另一个目录。 的index.html:
<html>
<form action='login.php' method='get'>
Username: <input type='text' name='user' /><br>
Password: <input type='password' name='pass' /><br>
<input type='submit' />
</form>
</html>
的login.php:
<?php
$user = $_POST['user'];
$conn = mysqli_connect('localhost', 'root' ,'a91c95n00', 'db_games2');
$sql = "SELECT username FROM userdata WHERE username='$user'";
$query = mysqli_query($conn, $sql);
$count = mysqli_num_rows($query);
if ($count == 0){
session_start();
$_SESSION['user'] = $user;
header('location:games.php');
}elseif ($count == 1){
header ('location:error.html');
}
?>
games.php:
<?php
session_start();
session_save_path('/var/www/html/1/');
session_save_path('/var/www/html/2/');
?>
<html>
<a href='http://76.29.204.37/1'>Product 1</a><br>
<a href='http://76.29.204.37/2'>Product 2</a>
</html>
/1/index.php
<?php
session_start();
if (!isset($_SESSION['user'])){
header ('location:error.html');
}elseif (isset($_SESSION['user'])){
header('location:success.php');
}
?>
每次进入产品1目录,都会转到error.html .. 设置会话时,应该转到success.php。请帮我!谢谢!