Page 1 of 1

Login redirection does not seem to work

Posted: Wed Apr 22, 2009 12:01 pm
by jdmfontz
I have a login script called login.php. When I place the following redirection lines as first lines in the script I want to execute to call my login.php if someone tries to execute it, for some reason the if condition does not get evaluated. I have spent couple of hours staring at those lines but nothing jumps out. Wondering if anyone can see the problem with that syntax:


<?
session_start();
if(! session_is_registered(myusername)){
header("location:login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>

. . .

rest of file here ...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Use Only HANDLING INSTRUCTIONS PROPRIETARY - SENSITIVE</title>
<style type="text/css">
hr.pme-hr { border: 0px solid; padding: 0px; margin: 0px; border-top-width: 1px; height: 1px; }
table.pme-main { border: #004d9c 1px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
table.pme-navigation { border: #004d9c 0px solid; border-collapse: collapse; border-spacing: 0px; width: 100%; }
td.pme-navigation-0, t

Re: Login redirection does not seem to work

Posted: Wed Apr 22, 2009 1:29 pm
by liljester
the php docs discourage using sessions_is_registered()..

typically i check to see if the value of a required session variable is set.. username for example.

Code: Select all

session_start();
if(!$_SESSION['username']) {
     header("Location: login.php");
     die();
}

Re: Login redirection does not seem to work

Posted: Thu Apr 23, 2009 8:58 am
by jdmfontz
Thanks. That worked. My php tutorial is quite old.