mysql - PHP 2 people logging in at the same time from the same computer pt.02 -
does alright login script
//player 1 login username , password $p1name = $_post['p1name']; $p1pass = $_post['p1pass']; //player 2 login username , password $p2name = $_post['p2name']; $p2pass = $_post['p2pass']; $connection = mysql_connect("db_host", "db_user", "db_pass"); mysql_select_db("db_name", $connection); get_user($p1name, $p1pass); get_user($p2name, $p2pass); $row = $result; $found = false; if(($row["username"] == $p1name && $row["password"] == sha1("$p1pass")) && ($row["username"] == $p2name && $row["password"] == sha1("$p2pass"))) { $found = true; break; } function get_user($username, $password) { $query = 'select * users'; $query .= ' username = ' . mysql_real_escape_string($username); $query .= ' , password = ' . mysql_real_escape_string(sha1($password)); $result = mysql_query($query); return mysql_fetch_assoc($result); }
<?php // player 1 login information $p1name = $_post['p1name']; $p1pass = $_post['p1pass']; // player 1 login information $p2name = $_post['p2name']; $p2pass = $_post['p2pass']; // check user information $player1 = get_user($p1name, $p1pass); $player2 = get_user($p2name, $p2pass); // has user been found? $found = array( 'player1' => false, 'player2' => false ); // check if use information matches if($player1['username'] == $p1name && $player1['password'] == $p1pass) { $found['player1'] = true; } if($player2['username'] == $p2name && $player2['password'] == $p2pass) { $found['player2'] = true; } function connect($db_host, $db_name, $db_pass, $db_table) { $connection = mysql_connect($db_host, $db_name, $db_pass); mysql_select_db($db_table, $connection); } function get_user($username, $password) { $query = 'select * users'; $query .= ' username = ' . mysql_real_escape_string($username); $query .= ' , password = ' . mysql_real_escape_string(sha1($password)); $result = mysql_query($query); return mysql_fetch_assoc($result); }
you needed create instances of returned user information check each players against own.
Comments
Post a Comment