1
我想顯示遊戲角色的屬性,這是用戶TABLE下的屬性。所以,我希望它顯示已登錄的用戶的特定屬性,因爲它應該在他的行中。我是否需要在會話中註冊用戶,因爲我沒有。會話?我如何顯示用戶行?
這是我用來獲取登錄時在
<?
if(isset($_POST['Login'])) {
if (ereg('[^A-Za-z0-9]', $_POST['name'])) {// before we fetch anything from the database we want to see if the user name is in the correct format.
echo "Invalid Username.";
}else{
$query = "SELECT password,id,login_ip FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result); // Search the database and get the password, id, and login ip that belongs to the name in the username field.
if(empty($row['id'])){
// check if the id exist and it isn't blank.
echo "Account doesn't exist.";
}else{
if(md5($_POST['password']) != $row['password']){
// if the account does exist this is matching the password with the password typed in the password field. notice to read the md5 hash we need to use the md5 function.
echo "Your password is incorrect.";
}else{
if(empty($row['login_ip'])){ // checks to see if the login ip has an ip already
$row['login_ip'] = $_SERVER['REMOTE_ADDR'];
}else{
$ip_information = explode("-", $row['login_ip']); // if the ip is different from the ip that is on the database it will store it
if (in_array($_SERVER['REMOTE_ADDR'], $ip_information)) {
$row['login_ip'] = $row['login_ip'];
}else{
$row['login_ip'] = $row['login_ip']."-".$_SERVER['REMOTE_ADDR'];
}
}
$_SESSION['user_id'] = $row['id'];// this line of code is very important. This saves the user id in the php session so we can use it in the game to display information to the user.
$result = mysql_query("UPDATE users SET userip='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',login_ip='".mysql_real_escape_string($row['login_ip'])."' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'")
or die(mysql_error());
// to test that the session saves well we are using the sessions id update the database with the ip information we have received.
header("Location: play.php"); // this header redirects me to the Sample.php i made earlier
}
}
}
}
?>
okay..but還是輸了,雖然 – Kelvin 2011-03-06 17:12:19
我也問一個問題有**你如何登錄到你的系統**。如果您不提供基本信息,我們如何幫助您解答問題?就像我說的,你需要找到你登錄的用戶。如果你知道這一點,你可以在你的查詢中使用它。如果您無法在此頁面上恢復該用戶標識,那麼您需要確保您可以。是的,那麼你可能會使用會話。 – Nanne 2011-03-06 17:21:15
好的>我會聯繫你的 – Kelvin 2011-03-06 20:31:25