And noticed they just use one function to stop sql would this work ?? The function they use is:
function mres($input){
if (get_magic_quotes_gpc()){
$input = stripslashes($input);
}
return mysql_real_escape_string($input);
}
And then here it is in my login script:
function mres($input){
if (get_magic_quotes_gpc()){
$input = stripslashes($input);
}
return mysql_real_escape_string($input);
}
if(isset($_POST['login']))
{
ini_set('session.cookie_httponly',true);
if(isset($_SESSION['last_ip']) == false){
$_SESSION['last_ip'] = $_SERVER['REMOTE_ADDR'];
}
if ($_SESSION['last_ip'] !== $_SERVER['REMOTE_ADDR']){
session_unset();
session_destroy();
}
$user= mres($_POST['username']);
$pass= mysql_real_escape_string($_POST['password']);
$pass2 = strip_tags($pass);
$pass1 = md5($pass2);
$mod = 1 ;
$sql = "SELECT * FROM users WHERE username='".$user."' AND password = '".$pass1."'";
$result = mysql_query($sql) or die(mysql_error());
$battle_get = mysql_fetch_array($result);
if ( $battle_get['mod'] == 1 ) {
$month = time() + 3600*24*30;
$hour = time() + 3600*1*1;
$LastLogin = date('l, M d, Y H:i:s');
$_SESSION['user'] = $_POST['username'];
setcookie("save_user", stripslashes(htmlentities($user22)), $hour);
setcookie("save_pass", stripslashes(htmlentities($user22)), $month);
$username = stripslashes(htmlentities($user22));
$result = mysql_query("UPDATE users SET LastLogin = '$LastLogin' WHERE username='$username'");
header("location: home.php");
}
}
Has you can see from my login script i check the ip on every page so that if some one logs in has bob with the ip has 1.2.3 then try's to edit the session and edits the username then it will log the person out and destory the session ( this works great )
But id just like to know does the function make em safe from sql injection ?
You can see ive used the function for the username because the password is md5
$user= mres($_POST['username']);
Also can some 1 explain what the function does ? And wouldn't i have to change $input to every virable i have ?
This post has been edited by rpgmaker: 25 May 2012 - 02:00 PM

New Topic/Question
Reply



MultiQuote







|