This is my code for login. when i try to login at 1st time it pass blank value to session.but when i go back to login page again & signin that time it successfully signin. i didnt understand whats wrong with this code?? plz help me.
session_unset();
session_start();
Global $i;
$root = $_SERVER['DOCUMENT_ROOT'];
include($root."/signinConfig.php");
function redirect($redirect=null)
{
header("Location : $redirect");
}
if (isset($_POST['submit']))
{
$check = mysql_query("SELECT * FROM user_reg WHERE `username` = '".$_POST['username']."'")or die("Dont Dare To Hack");
$check2 = mysql_numrows($check);
if ($check2 == 0)
{
die('That user does not exist in our database. <a href="../Signup/registration.php" style="text-decoration: none;">Click Here To Register</a>');
}
else
{
$i=0;
$password = mysql_result($check,$i,"password");
$_POST['pass'] = stripslashes($_POST['pass']);
$pass = md5($_POST['pass']);
if ($pass == $password)
{
$_SESSION['username']= mysql_result($check,$i,"username");
mysql_close();
redirect("/User_CP/user_cp.php");
}
else
{
die('Incorrect password, please try again.');
}
}
}//after this html code take place
config dosyasında i veritabanı bağlantı kodu saklamak & oturum kodu sona erer. işte burada
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1000)) { // last request was more than 30 minates ago
session_destroy(); // destroy session data in storage
session_unset(); // unset $_SESSION variable for the runtime
}
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp