-1

我想做登录页面。当我输入详细信息时,会出现问题。

登录.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>

电影1.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>

当我尝试登录用户名:Joe 和密码:12345。我会得到错误。注意:未定义索引:在第 4 行传入 C:\xampp\htdocs\book\book\movie1.php 我的 PHP 版本是 5.4.7。

电影网站.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>
4

1 回答 1

2

改变,

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

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

由于无效的 HTML 标记(缺少 =),PHP 不会看到输入“通过”。所以它不会出现在 $_POST 数组中,所以它会给你一个未定义的索引错误,因为你试图引用不存在的东西。

于 2013-07-07T14:01:45.580 回答