Jump to content

Recommended Posts

I coded a simple three part register/login script, the register page, the login page, and the member page.  I coded this with a PHP pocket reference book.

 

So now, I face the problem of making php pages login protected.

 

I added this code to the pages that I want to be login protected:

 

<?php
session_start();
if ( @$_SESSION['cookie'] != "yes" )
{
header("Location: login.php");
exit ();
}
?>

 

The redirect works to login.php, but when I login and go to that page (for example, test.php), it redirects me to the member page.

 

What am I doing wrong??

 

Thanks in advance!

Avoid using the @.

 

Instead I would use this:

<?php
session_start();
if (!isset($_SESSION['cookie']) || $_SESSION['cookie'] != "yes" ) {
   header("Location: login.php");
   exit ();
}
?>

 

As far as why it is redirecting to the member page, you need to post the full code for that page. As I do not see anywhere there that would redirect you to the members page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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