Jump to content

Problem with simple login script I coded


jdock1

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.

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.