matio Posted December 21, 2009 Share Posted December 21, 2009 Hi everyone, I'm trying to make a login page, I have two files -- that are important to this post: 1) login.php: <?php require_once("include/db.php"); session_start(); $user = $_POST['user']; $pass = $_POST['password']; if (user && pass){ $con = db_connect(); $sha = sha1($pass); $result = $con->query("select * from users where username='$user' and passwrd='$sha';"); if ($result->num_rows == 0){ echo '<div style="width:790px;min-height:700px;margin:auto;background:white">'; include_once("include/header.php"); include_once("include/navbar.php"); echo 'Wrong username or password -- please try again'; echo $sha; exit; } $_SESSION['valid_user'] = $user; if($_SESSION['valid_user'] == "admin"){ header("Location: admin.php"); exit; } header("Location: member.php"); exit; }else{ include_once("include/header.php"); include_once("include/navbar.php"); echo 'Please go back and fill in all required details'; } ?> 2) admin.php: <?php require_once("include/db.php"); echo '<div style="width:790px;min-height:700px;margin:auto;background:white">'; include_once("include/header.php"); include_once("include/navbar.php"); echo '<br />'; if($_SESSION['valid_user'] == "admin"){ }else{ echo 'You cannot view this page -- please login'; } ?> I login as admin and get redirected to admin.php -- but when I get there it says that I cannot view this page. Don't know why this doesn't work seen as I'm using the same 'if' conditions... Link to comment https://forums.phpfreaks.com/topic/185885-problem-with-session-control-not-being-created/ Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2009 Share Posted December 21, 2009 you require to put session_start() in your admin.php too, I see its not present Link to comment https://forums.phpfreaks.com/topic/185885-problem-with-session-control-not-being-created/#findComment-981579 Share on other sites More sharing options...
matio Posted December 21, 2009 Author Share Posted December 21, 2009 Thanks for the quick reply -- it worked. Better re-read my php book! Link to comment https://forums.phpfreaks.com/topic/185885-problem-with-session-control-not-being-created/#findComment-981580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.