auriaks
03-30-2010, 07:35 AM
Hey,
I had problems with malicious this week, so I want to ask for help.
I have session like this: (This is working when enter correct information)
$password = md5($_POST['password']);
$nick = $_POST['nick'];
$password = mysql_real_escape_string($password);
$nick = mysql_real_escape_string($nick);
$nick = strtolower($nick);
$q = mysql_query("SELECT * FROM reg_users WHERE nick='$nick' AND password='$password'") or die(mysql_error());
$r = mysql_fetch_array( $q ) or die(mysql_error());
session_start();
$_SESSION['nick'] = $nick;
$_SESSION['password'] = $password;
$_SESSION['authID'] = $r['id'];
and script into each safe page:
<?php
$IP = $_SERVER['REMOTE_ADDR'];
session_start(); // begin session
if(isset($_SESSION['authID'])) {
include $_SERVER['DOCUMENT_ROOT'] . '/game/reg_conn/db_conn.php';
$dates = date("Y-m-d");
$times = date("H:i:s");
$upnick = $_SESSION['nick'];
$quer = mysql_query("SELECT * FROM players WHERE nikas='$upnick'");
if (mysql_num_rows($quer) > 0) {header("Location: index.php");} else {header("Location: register.php");}
} else {
header("Location: ../login.php"); // if user is not loggged in.
}
?>
How I can improve this security, or it is good enough???
I had problems with malicious this week, so I want to ask for help.
I have session like this: (This is working when enter correct information)
$password = md5($_POST['password']);
$nick = $_POST['nick'];
$password = mysql_real_escape_string($password);
$nick = mysql_real_escape_string($nick);
$nick = strtolower($nick);
$q = mysql_query("SELECT * FROM reg_users WHERE nick='$nick' AND password='$password'") or die(mysql_error());
$r = mysql_fetch_array( $q ) or die(mysql_error());
session_start();
$_SESSION['nick'] = $nick;
$_SESSION['password'] = $password;
$_SESSION['authID'] = $r['id'];
and script into each safe page:
<?php
$IP = $_SERVER['REMOTE_ADDR'];
session_start(); // begin session
if(isset($_SESSION['authID'])) {
include $_SERVER['DOCUMENT_ROOT'] . '/game/reg_conn/db_conn.php';
$dates = date("Y-m-d");
$times = date("H:i:s");
$upnick = $_SESSION['nick'];
$quer = mysql_query("SELECT * FROM players WHERE nikas='$upnick'");
if (mysql_num_rows($quer) > 0) {header("Location: index.php");} else {header("Location: register.php");}
} else {
header("Location: ../login.php"); // if user is not loggged in.
}
?>
How I can improve this security, or it is good enough???