2013-07-07 61 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