Jump to content

session to prevent access


searls03

Recommended Posts

On your login processing page, if someone logs in successfully (i.e. puts in the correct username and password), then you should add a line like:

 

<?php
  $_SESSION['logged_in'] = true;
?>

 

Then on each page you want to protect, at the top of the page should be:

 

  if (!isset($_SESSION['logged_in'])){
    header("Location: login.php");
  }

 

Then when they log out, you need to:

 

  unset($_SESSION['logged_in']);

 

Remember to include session_start(); at the top of any page where you want to reference or set session variables.

I have just tried to use this, and it seems it sends me to the login page even if I have logged in. 

Here is what I have:

<?php
if (!isset($_SESSION['logged_in']))
{
	echo"failed";
	header("Location: fail.html");
}
else
{
	echo("loaded<br>");
}
?>
rest of page...

And on the login page it sets the login with:

$_SESSION['logged_in'] = true;

But wheter I use the login, correctly, or just go straight to that page, I still get sent to the failed.html  I would appreciate any help.

 

 

@OP: Perhaps you could just give the admins the right password, or a different login page than the other users.

 

 

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.