• (2 Pages)
  • +
  • 1
  • 2

Text Based Mafia Game || Login, Layout/design Part 3 Making a login page and having a an inside game design. Rate Topic: ***** 1 Votes

#16 Shadowing  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 35
  • Joined: 26-November 11

Posted 22 January 2013 - 03:33 AM

Hey sakred I don't see errors in your code. Add this instead of the error message you have now. And tell me what you get.
Echo "invalid password".$row['password'];

Also always use lower case on every thing. Including data base columns and HTML attributes. Name,I'd etc...


View Postsakred, on 21 January 2013 - 10:58 PM, said:

I can't seem to log in. It always says invalid password when it's correct according to the database. Also if i go back to the register.php page and make a new account it doesn't log the ip. Or nothing ever gets stored into the login_ip row of the database. I'm not sure what i'm doing wrong. Some help would be MUCH appreciated. Thanks. Oh and i'll put the code for my index page and maybe you will see something i don't. And another side note. My database is "Users" instead of "users". So that's why mine is capitalized.

<? include_once("connect.php"); ?>
<? require 'functions.php'; ?>
<html>
<head>
<title>Index</title>
</head>
<body>


<?
if(isset($_POST['Login'])) {

       if (ereg('/^[A-Za-z0-9]{5,20}$/', $_POST['Username'])) {// Before we fetch anything from the database we want to see if there 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 datatbase 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 exists 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 field. Notice to read the md5 has 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 on the database it will store it.
				                 if (in_array($_SERVER['REMOTE_ADDR'], $ip_information)) {
								 $row['loging_ip'] = $row['login_ip']."-".$_SERVER['REMOTE_ADDR'];
				          }
						 }
					$_SESSION['user_id'] = $row['id']; // This line of code is ver important. This saves the user id in the php session so we can use it in the game to display information to the user.
					$_SESSION['login_time'] = time(); // stores the login time of 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 sesssions id update the database with the ip information we have received.
					
					header("Location: Sample.php"); // This header redirects me to the Sample.php i made earlier
					
				
					 }
				     }
			}		 
		}
?>




<form id="form1" name="form1" method="post" action=""><center>
GAME LOGIN
<br/>
<br/>
Username:
<input type="text" name="Username" id="Username"/>
<br/><br/>
Password:
<input type="password" name="password" id="password" />
<br/> <br/>
<input type="submit" name="Login" id="Login" value="Login" />
</center>
</form>

</body>
</html>


This post has been edited by Shadowing: 22 January 2013 - 03:34 AM

Was This Post Helpful? 1
  • +
  • -

#17 Darkvortex  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 19-February 13

Posted 24 February 2013 - 11:51 PM

Thanks my friend this tutorial give me great help.
Was This Post Helpful? 0
  • +
  • -

#18 Lightme  Icon User is online

  • New D.I.C Head

Reputation: 0
  • Posts: 36
  • Joined: 06-March 10

Posted 30 May 2014 - 06:54 AM

The logout with me doesn't work. Plus I can acces usersonline.php anytime I feel like too.
Was This Post Helpful? 0
  • +
  • -

#19 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,466
  • Joined: 12-June 08

Posted 30 May 2014 - 07:31 AM

That's a bummer. Did you work something out to fix either issue?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2