我在注册会话时遇到问题,它总是有效,但有一次,它没有。我使用PHP 版本 5.2,阅读了一些要更改session_register("");
的内容$_SESSION('') = $$blabla;
,所以我这样做了,但这也没有用。
这是我的代码:
<?
ob_start();
$host="localhost"; // Host name
$username="transrpt_transrp"; // Mysql username
$password="******************"; // Mysql password
$db_name="transrpt_transrp"; // Database name
$tbl_name="PlayerData"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword= hash('whirlpool', $_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 Name='$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!=0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$resultt = mysql_query("SELECT * FROM PlayerData WHERE Name='$myusername'");
$row = mysql_fetch_array($resultt);
$playerlevel = $row['PlayerLevel'];
$_SESSION['myusername'] = $$myusername;
$_SESSION['mypassword'] = $$mypassword;
$_SESSION['playerlevel'] = $$playerlevel;
header("location:index.php");
}
else {
echo "Wrong username or password";
}
ob_end_flush();
?>