tonit Posted April 29, 2011 Share Posted April 29, 2011 Hello, I'm trying to test a simple login system without a db, just for testing purposes. I have created a php file that checks if the username and pass are valid and register a session. <?php session_start(); define("ADMINUSER", "user"); define("ADMINPASSWORD", "pass"); $user = $_POST['user']; $pass = $_POST['pass']; if (($user==ADMINUSER) && ($pass==ADMINPASSWORD)) { $_SESSION['logged_in'] = true; header("Location: main.php"); } else { header("Location: auth.php?flag=wrong"); } ?> and include this in other files to check if the user is logged in: <? session_start(); if ($_SESSION['logged_in'] != true) { header("Location: auth.php?flag=not"); exit; } ?> But this doesn't seem to work, as I closed the window, clear my cookies and shutdown my PC and when I try to open it again and it doesn't redirect me to the login page(auth.php). What am I doing wrong ? Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/235091-php-session-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 29, 2011 Share Posted April 29, 2011 What does a 'view source' in your browser show for the page with the second piece of code in it? Link to comment https://forums.phpfreaks.com/topic/235091-php-session-not-working/#findComment-1208203 Share on other sites More sharing options...
fugix Posted April 29, 2011 Share Posted April 29, 2011 so if i am reading correctly...you remain logged/session remains true? Link to comment https://forums.phpfreaks.com/topic/235091-php-session-not-working/#findComment-1208206 Share on other sites More sharing options...
tonit Posted April 29, 2011 Author Share Posted April 29, 2011 What does a 'view source' in your browser show for the page with the second piece of code in it? Ah, I changed the "<?" to "<?php" and it's working right now. Thank you very much, if it's that what you meant ^^. Link to comment https://forums.phpfreaks.com/topic/235091-php-session-not-working/#findComment-1208219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.