Jump to content

(login) (logout) show hide them depending if u r or not


brad12345

Recommended Posts

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

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>

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>   
                                                                

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.