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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>   
                                                                

Link to comment
Share on other sites

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>";
}
?>

Link to comment
Share on other sites

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.