after checking if the login was successful i want to create a session to check to see if a user is logged in or not can any one help me with that plz session_start(); include ('connect.php'); $user = $_POST['u_name']; $pass = $_POST['pwd']; if(!$user){ echo "please enter your username. <br>"; } if(!$pass){ echo "please enter your password"; } if ($user && $pass){ $sql= ("SELECT * FROM user_accounts WHERE username = '$user' AND password = '$pass'"); $res = mysql_query($sql); $count = mysql_num_rows($res); if ($count ==0){ echo "ur user name or password may be incorrect! try again"; } ELSE { if ($count ==1){ $row = mysql_fetch_array($res); echo "u have been logged in successfully"; } } } PHP:
You need to set a session variable when they login, and check it every time they load another page that they need to be logged in to see. In the success statement add something like this: $_SESSION['loggedin'] = 1; PHP: Then on any page they need to be logged in add this at the top: if(!isset($_SESSION['loggedin']){ // if they haven't logged in and set the $_SESSION variable header("Location: http://www.yoursite.com/login.php"); // redirect them to login.php } PHP: Let me know how that works for ya!