我在學校項目中遇到問題。我已經問了我的老師和同學,但他們都不知道該怎麼做。無法從SESSION獲得變量
我製作了基於瀏覽器的遊戲,顯然它需要有用戶。這就是問題所在。
當我登錄並進入驗證頁面時,它從POST中提取信息就好了,但是當我在驗證中將信息插入SESSION中,然後轉到主頁索引時,它拒絕獲取SESSION信息,而我只是得到一個錯誤。
注意,design2.php與登錄過程沒有任何關係。
下面的代碼:
的login.php
<?php
include_once'design2.php';
?>
<div id="center">
<form method="POST" action="authenticate.php">
User Name <input id="input" type="text" name="player" size="21">
Password <input id="input" type="password" name="password" size="21">
<br>
<input type="submit" value="Login" name="submit">
<br><br>Not Registered? <a id='underlinelink' href='register.php'>Register</a>
Authenticate.php
<?php
include_once 'connect.php';
?>
<div id="center">
<?php
if (isset($_POST['submit']))
{
$player=$_POST['player'];
$password=$_POST['password'];
$player=strip_tags($player);
$password=strip_tags($password);
$password=md5($password);
$query = "select name, password from players where name='$player' and password='$password'";
$result = mysql_query($query) or die("Could not query players");
$result2 = mysql_fetch_array($result);
if ($result2)
{
$_SESSION['player'] = $player;
echo "<big>Logged in successfully<br>";
echo "<A id='underlinelink' href='index.php'>Continue</a></big>";
}
else
{
echo "<big>Wrong username or password.<A id='underlinelink' href='login.php'>Try Again</a></big>";
}
}
?>
</div>
Design.php(這是每一個網頁在我的網站)
<?php
include_once 'connect.php';
?>
<link href="stilark.css" rel="stylesheet" type="css" />
<?php
session_start();
if(isset($_SESSION['player']))
$player = $_SESSION['player'];
else
echo "could not logg in, <a href='login.php'>Go back</a>";
exit;
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
?>
請幫忙,ir最終需要在其到期前完成。
做'在session_start添加
session_start();
。因此''__ESSION ['player'] = $ player;' – Havelock