geloo Posted November 16, 2010 Share Posted November 16, 2010 Hallo my problems is something with the session in my script as it redirects even when i logged in can someone help out please.. the code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> </title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="post"> Username:<input type="text" name="username" /> Password:<input type="password" name="password" /> <input type="submit" name="submit" value="submit" /> </form> <?php $host = '---'; $user = '---'; $pass = '---'; $db = '---'; $connect = mysql_connect($host, $user, $pass) or die ('Could not connect'); $database = mysql_select_db($db) or die ('Could not connect'); $username = $_POST['username']; $password = $_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql= " SELECT * FROM Users WHERE username= '".$username."' AND password = '".$password."' "; $result = mysql_query($sql); if(mysql_num_rows($result) == 1){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; header("location: login_succes.php"); } ?> </body> </html> code login_succes.php <?php session_start(); if(!isset($_SESSION['username'])){ header('location: login.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> </title> <link rel="stylesheet" href="stylesheet.css" type="text/css" /> </head> <body> login succesfull </body> </html> Link to comment https://forums.phpfreaks.com/topic/218835-need-help-with-session-in-script/ Share on other sites More sharing options...
revraz Posted November 16, 2010 Share Posted November 16, 2010 You dont have session_start in your first script. Also, I am not sure how your header in the first script is even working at all, seeing how you have output before it. Link to comment https://forums.phpfreaks.com/topic/218835-need-help-with-session-in-script/#findComment-1134926 Share on other sites More sharing options...
geloo Posted November 16, 2010 Author Share Posted November 16, 2010 Thanks worked:) Link to comment https://forums.phpfreaks.com/topic/218835-need-help-with-session-in-script/#findComment-1134931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.