Hi there,
I have a question related to Session. I made a login screen and all pages except than the login page should be secure, so no one can access to any page unless access from the main login page, so I did this coding but even if someone checked the option of "Remember Me" and if he/she closed the browser and come back again he can enter access any pages because the Cookies is still available because I made it here for 2 hours so after that no one can access the page, and I made another Logout so if someone press it it will remove the cookies so has to login again. So any solution for the problem.
This code I putted in my important pages
And this is my login screen.
I have a question related to Session. I made a login screen and all pages except than the login page should be secure, so no one can access to any page unless access from the main login page, so I did this coding but even if someone checked the option of "Remember Me" and if he/she closed the browser and come back again he can enter access any pages because the Cookies is still available because I made it here for 2 hours so after that no one can access the page, and I made another Logout so if someone press it it will remove the cookies so has to login again. So any solution for the problem.
This code I putted in my important pages
Code:
<?php include 'functions.php'; session_start(); if($_SESSION["a"]!=1) { header("location:index.php"); }
And this is my login screen.
Code:
<?php include 'functions.php'; if ($_POST["login"]) { global $username; $username = $_POST['username']; $password = $_POST['password']; $rememberme = $_POST['rememberme']; if($username&&$password) { $login = mysql_query("SELECT * FROM usersystem WHERE username='$username'"); while ($row = mysql_fetch_assoc($login)) { $db_password = $row['userpass']; if(md5($password)==$db_password) $loginok = TRUE; else $loginok = FALSE; if ($loginok==TRUE) { $_SESSION["a"] = 1; if ($rememberme=="on") setcookie("username", $username, time()+7200); else if ($rememberme=="") $_SESSION['username']== $username; $_SESSION['username'] =$_POST['username']; header("Location: redirectpage.php"); exit(); } } } else die("Please enter a username and password"); } ?>
Comment