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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 ^^. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.