Session Variable shows in one part of page but not other.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jdhorton77
Forum Commoner
Posts: 56
Joined: Tue Nov 07, 2006 3:29 pm
Location: Charlotte, NC

Session Variable shows in one part of page but not other.

Post by jdhorton77 »

I have a customer account page that is just in development right now. And I have a php file that is included in all pages that is a menu.php file for the menu bar. When the customer is logged in it's supposed to show an extra link to the orders page. Problem is that it works on the home page and not the customer account page. But also on the customer account page I have an if statement checking to see if the variable is set. The if statement shows that the variable is set, but on the same page when I include the menu.php file it isn't set. If anyone can help me I would greatly appreciate it. Here's the code.

menu.php (partial code)

Code: Select all

<html>
<?php
session_start();
?>


<TABLE WIDTH=800 BORDER=0  CELLPADDING=0 CELLSPACING=0 align="center">
   <tr>
      <td width="800" colspan="2"> <img src="http://weprint4you.com/images/topbar.jpg"> </td>
   </tr>
      <TR >
         <TD width="200" height="30">
            <IMG SRC="http://weprint4you.com/images/menu_01.gif" ALT="menu_01.gif"></TD>
         <TD background="http://weprint4you.com/images/menu_02.gif" align="center" width="600" height="30">&nbsp; | &nbsp;
	
                <?php if ($_SESSION['customerLoggedIn'] == 1){ ?>
	<a href="https://weprint4you.com/customerorders.php">Customer Orders</a>&nbsp; | &nbsp;
	<a href="http://weprint4you.com/createorder.php">Purchase New Print</a>&nbsp; | &nbsp;
	<a href="http://weprint4you.com/pricing.php">Products & Pricing</a>&nbsp; | &nbsp;
	<a href="http://weprint4you.com/contact.php">Contact Us</a>&nbsp; | &nbsp;
			
                <?php } else if ($_SESSION['employeeLoggedIn'] == 1) { ?>
	<a href="../httpdocs/employeeSales.php">Employee Sales</a>&nbsp; | &nbsp;
	<a href="../httpdocs/employeePromos.php">Promotional Codes</a>&nbsp; | &nbsp;
	
                <?php } else {?>
	<a href="http://weprint4you.com/createorder.php">Purchase New Print</a>&nbsp; | &nbsp;
	<a href="http://weprint4you.com/pricing.php">Products & Pricing</a>&nbsp; | &nbsp;
	<a href="http://weprint4you.com/contact.php">Contact Us</a>&nbsp; | &nbsp;
	<?php } ?>
     
       </td>
customeraccount.php (complete code)

Code: Select all

<?php
	session_start();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Customer Account</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php include("http://weprint4you.com/menu.php"); ?>

<p>Went Through</p>
<?php if ($_SESSION['customerLoggedIn'] == 1) 
	{
	echo 'customer logged in';
	}
	else
	{
	echo 'customer not logged in';
	}
?>

</body>
</html>
Thanks again for the help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in menu.php the session start up request happens after headers have been sent (by "<html>".) Move the start up code to the absolute first thing in the file. No spaces or carriage returns can come before it.
Post Reply