Jump to content

PHP Session not Working


tonit

Recommended Posts

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
Share on other sites

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
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.