Page 1 of 1

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

Posted: Tue Jan 09, 2007 10:58 pm
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.

Posted: Wed Jan 10, 2007 12:07 am
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.