2013-07-07 44 views
-1

我想做登錄頁面。當我輸入詳細信息時,出現問題。未定義的索引錯誤。 PHP版本:5.4.7

的login.php

<?php 
session_unset(); 
?> 
<html> 
<head> 
</head> 
<body> 
<form action="movie1.php" method="post"> 
<p>Enter username: 
<input type="text" name="user"/> 
</p> 
<p>Enter Password: 
<input type="password" name "pass"/></p> 
<p> 
<input type="submit" name="submit" value="Submit" /></p> 
</form> 
</body> 
</html> 

movie1.php

<?php 
session_start(); 
$_SESSION['username'] = $_POST['user']; 
$_SESSION['userpass'] = $_POST['pass']; 
$_SESSION['authuser'] = 0; 
if (($_SESSION['username'] == 'Joe') and ($_SESSION['userpass'] == '12345')) 
{ 
$_SESSION ['authuser']=1; 
} 
else { 
echo 'you can not enter here.'; 
exit(); 
} 

?> 

<html> 

<?php 
$myfavmovie = urlencode ('Life of brain'); 
echo "<a href=\"moviesite.php?favmovie=$myfavmovie\">"; 
echo "click here for more information"; 
echo "</a>"; 
?> 

</html> 

當我嘗試登錄用戶名:喬和密碼:12345。我會得到錯誤。 注意:Undefined index:傳入第4行的C:\ xampp \ htdocs \ book \ book \ movie1.php 我的PHP版本是5.4.7。

moviesite.php

<?php 
session_start(); 
if ($_SESSION['authuser'] != 1) 
{echo "you don't enter here."; 
exit(); 
} 

?> 
<html> 
<head > 
<title > My Movie Site - <?php echo $_GET['favmovie']; ?> </title> 
</head > 
<?php 
echo "welcome our website, " ; 
echo $_SESSION['username']; 
echo "."."<br>"; 
echo "my favorite film is "; 
echo $_GET['favmovie']; 
echo "<br>"; 
$movierate= 5; 
echo "my point is"." ".$movierate; 

?> 
</html> 

回答

2

變化,

<input type="password" name "pass"/></p> 

<input type="password" name="pass"/></p> 

由於無效HTML標記(缺失=),PHP將不會看到輸入「的通過」。 所以它不會出現在$ _POST數組中,所以它會給你一個未定義的索引錯誤,因爲你試圖引用一些不存在的東西。

+0

感謝您的回覆。現在正在工作 – Afsar