有问题,我登录的PHP代码..PHP登录脚本不会直接登录成功页面提交一次
我有一个提交到“checklogin.php”,这是下面的代码一种基本形式。一旦你提交它只是停留在“checklogin.php”上的登录凭证,并且不显示任何内容。有没有人有任何想法?
<?php
$host="localhost"; // Host name
$username="alex"; // Mysql username
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about 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=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_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”结果中的第一行 – esdebon
此代码来自与其他人['一天前发布的帖子](http://stackoverflow.com/q/22354466/)相同的地方。我没有碰这个;太多移动部件。 ['This'](http://www.phpeasystep.com/phptu/6.html)最有可能是它的起源。 –
@ Fred-ii- Goddamnit。我们可以找出他的网站,并
打他脸请他很好地打倒那个可怕的网站。 – PeeHaa