嘿伙计们,我正在创建一个简单的登录脚本。当我输入有效的用户名和密码时,该函数调用 login_success.php 但没有任何反应。我使用以下链接获取资源:
- http://www.phpeasystep.com/phptu/6.html
- http://forum.codecall.net/topic/44787-creating-loginregistration-forms-with-php/#axzz2DwhIYfzj
- http://frozenade.wordpress.com/2007/11/24/how-to-create-login-page-in-php-and-mysql-with-session/
我也在这个网站上搜索了一些帖子。您的帮助总是值得赞赏的。这是代码:
登录.php
<?php
ob_start();
include 'connect.php';
$usernamefield = $_POST['usernamefield'];
$passwordfield = $_POST['passwordfield'];
$sql = "SELECT * FROM login WHERE username = '$usernamefield' and password = '$passwordfield'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($count == 1) {
session_register("usernamefield");
session_register("passwordfield");
header("Location: login_success.php");
} else {
echo "Invalid username or password";
}
exit();
?>
login_success.php
<?php
session_start();
if(!session_is_registered(myusername)){
header("Location: login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>