Jump to content

session to prevent access


searls03
 Share

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.