brad12345 Posted June 24, 2008 Share Posted June 24, 2008 hi all trying to get php to either only show login link in my sites menu or logout link in my sites menu depending on if the user is logged in or not, after my user logs in the "loginSuccess.php" page it works only showing the logout link but as soon as i go to another page like "index.php" it losses track of this that a session is active or wateva and only shows the login link even though the user is already logged in. <?php session_start(); if(!session_is_registered(CustID)){ header("location:login.php"); } include ('serverConnect.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="stylesheet.css" /></head> <title>Untitled Document</title> </head> <body> <div id="wrap"> <div class="header"></div> <div class="headerSpacer"><a href="index.php">Home</a> | <?php if(!session_is_registered(CustID)) { echo "<a href='login.php'>Login</a>"; } elseif(session_is_registered(CustID)) { echo "<a href='logout.php'>Logout</a>"; } ?> </div> thanks for any help Quote Link to comment Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 Dump the session_is_registered() and go with... <?php if (!$_SESSION['CustID']) { // show login link } else { // show logout link } ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 24, 2008 Share Posted June 24, 2008 Some newer version of php come the register globals directive set to "off".. use this: <?php session_start(); if(!isset($_SESSION['CustID'])){ header("location:login.php"); } include ('serverConnect.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="stylesheet.css" /></head> <title>Untitled Document</title> </head> <body> <div id="wrap"> <div class="header"></div> <div class="headerSpacer"><a href="index.php">Home</a> | <?php if(!isset($_SESSION['CustID'])){ { echo "<a href='login.php'>Login</a>"; } if(isset($_SESSION['CustID'])){ { echo "<a href='logout.php'>Logout</a>"; } ?> </div> Quote Link to comment Share on other sites More sharing options...
brad12345 Posted June 24, 2008 Author Share Posted June 24, 2008 thanks for quick reply getting error Parse error: syntax error, unexpected $end in /home/it224/bradk/public_html/finalProject/index.php on line 32 <?php include ('serverConnect.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="stylesheet.css" /></head> <title>Untitled Document</title> </head> <body> <div id="wrap"> <div class="header"></div> <div class="headerSpacer"><a href="index.php">Home</a> | <?php if(!isset($_SESSION['CustID'])){ { echo "<a href='login.php'>Login</a>"; } if(isset($_SESSION['CustID'])){ { echo "<a href='logout.php'>Logout</a>"; } ?> </div> <div class="content"></div> <div class="bottom"></div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 You have some extra brackets in there. Change it to this. <?php if(!isset($_SESSION['CustID'])) { echo "<a href='login.php'>Login</a>"; } if(isset($_SESSION['CustID'])) { echo "<a href='logout.php'>Logout</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted June 24, 2008 Share Posted June 24, 2008 Ya. Sorry, my mistake I think. Quote Link to comment Share on other sites More sharing options...
brad12345 Posted June 24, 2008 Author Share Posted June 24, 2008 hmm still does the same thing.....? any other ideas? i mean original proplem Quote Link to comment Share on other sites More sharing options...
gijew Posted June 24, 2008 Share Posted June 24, 2008 Did you put the session_start() back up there? I noticed it wasn't there after a few posts. Quote Link to comment Share on other sites More sharing options...
brad12345 Posted June 24, 2008 Author Share Posted June 24, 2008 ive got it once on the "loginSuccess.php" page do i have to add it to everypage at the top? i thought it just was a once of thing untill u click logout when the session stops? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.