我正在尝试创建一个简单的登录系统。当我运行登录表单(使用正确的用户名和密码)时,它似乎不能运行php。有什么建议吗?
<?php
$host="linuxserver"; // Host name
$username="jparry2"; // Mysql username
$password=""; // Mysql password
$db_name="jparry2"; // Database name
$tbl_name="customer"; // Table name
// Connect to server and select databse.
mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysqli_query($sql);
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
<html>
<body>
</body>
</html>编辑添加的登录表单代码
<html>
<head><title>Login</title></head>
<body>
<form action='checklogin.php'
method='POST' style='margin: .5in'>
<p><label for='user_name' style='font-weight: bold;
padding-bottom: 1em'>USER ID: </label>
<input type='text' name='myusername' id='myusername'
value='' /></p>
<p><label for='password' style= 'font-weight: bold'>Password: </label>
<input type='password' name='mypassword' id='mypassword'
value='' /></p>
<p><input type='submit' value='Login'> </p>
<input type='hidden' name='sent' value='yes'/>
<a href= "/home/jparry2/public_html/register.php">Register</a>
</form>
</body>
</html>发布于 2009-12-11 01:38:37
如果你的浏览器要求你下载php文件,这意味着php解释器没有被调用。也就是说,您没有正确安装或配置它。
发布于 2009-12-11 01:06:16
您是否收到任何错误消息?在我看来没问题。例如,您是否尝试过在if块中回显某些内容?这可能会帮助你理解哪里出了问题。
您可以检查或尝试以下内容:
header()函数之前没有向浏览器输出任何内容。如果您关闭了error_reporting并将某些内容输出到浏览器,则使用header()将导致致命错误,这可能会导致空白页面。代码中的其他一些注释:
你不需要把变量放在双引号里,它们会自己起作用:,如果你在做mysql_real_escape_string,mysqli_select_db("$db_name")变成了,
mysqli_select_db("$db_name"),to,to,stripslashes()。后者将自己处理这项工作。发布于 2009-12-11 01:09:13
在某些浏览器中,Location头是区分大小写的,因此header("location:login_success.php");调用可能无法正常工作( header documentation page上的comment表明这是在IE7中发生的)。尝试将位置中的l大写。
https://stackoverflow.com/questions/1882407
复制相似问题