Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading sessions

Status
Not open for further replies.

csphard

Programmer
Apr 5, 2002
194
US
<?php $session_start(); ?>
using sessions


I have a login page called login.php. When the user press submit
on that page I send the user to a page called checklogin.php.

On this page I have an include

<?php require_once("includes/session.php"); ?>

in this include is
<?php
session_start();
?>

This works. My problem is that I have a menu that is included where I only want
to display a certain part of it is the user is log on and it does not work and it is
displayed below. The problem is that I can not echo out the session.

I thought with a require_once I would not have to use this include a second time.

and when I try to use it I get
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\melissahardaway\index.php:11) in C:\xampp\htdocs\melissahardaway\includes\session.php on line 2

What do I need to do to access this session.

sidemenu.php
<div id="sidebar">
<ul>
<li><a href="index.php">home</a></li>
<li><a href="about_us.php">ABOUT US</a></li>
<li><a href="in_foreclosure.php">in foreclosure</a></li>
<li><a href="property_management.php">PROPERTY MANAGEMENT</a></li>
<li><a href="address_report.php">Residential INVENTORY</a></li>
<li><a href="resume.php">RESUME</a></li>
<li><a href="contact_us.php">CONTACT US</a></li>
</ul>
<?php echo $_SESSION['username']; ?>
<?php echo "test"; ?>
<?php
if ($_SESSION['username'] == 'testme')
{
echo "<h2>admin</h2><ul>";
echo "<li><a href=\"address_input.php\">add address</a></li>";
echo "<li><a href=\"delete_srh.php\">delete address</a></li>";
echo "<li><a href=\"address_srh.php\">update address</a></li>";
echo "</ul>";
}
?>
</div>


checklogin.php

<?php require_once("includes/session.php"); ?>
<?php include "includes/dbstore.php"; ?>
<?php include "includes/functions.php"; ?>
<?php
$username = $_POST['username'];
$password = $_POST['password'];
///$hashed_password = sha1($password);
$hashed_password = $_POST['password'];
//$session_start();
$sql = "select * from tbl_users where username = '" . $_POST["username"] . "' and hashed_password='" . $hashed_password . "'";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1)
{
$found_user = mysql_fetch_array($result);
redirect_to("address_input.php");
$_SESSION['username'] = $found_user['username'];
} else {
redirect_to("login.php");
}
?>



Howard
 
Code:
<?php $session_start(); ?>
this is incorrect. you should not prepend $ signs to function names unless you are using variable functions.
 
I corrected that and ran it and still have the same problem.
session.php include
<?php
session_start();
?>

side_menu.php
<?php require_once("includes/session.php"); ?>
<div id="sidebar">
<ul>
<li><a href="index.php">home</a></li>
<li><a href="about_us.php">ABOUT US</a></li>
<li><a href="in_foreclosure.php">in foreclosure</a></li>
<li><a href="property_management.php">PROPERTY MANAGEMENT</a></li>
<li><a href="address_report.php">Residential INVENTORY</a></li>
<li><a href="resume.php">RESUME</a></li>
<li><a href="contact_us.php">CONTACT US</a></li>
</ul>
<?php echo $_SESSION['username']; ?>
<?php echo "howard"; ?>
<?php
if ($_SESSION['username'] == 'hharda9791')
{
echo "<h2>admin</h2><ul>";
echo "<li><a href=\"address_input.php\">add address</a></li>";
echo "<li><a href=\"delete_srh.php\">delete address</a></li>";
echo "<li><a href=\"address_srh.php\">update address</a></li>";
echo "</ul>";
}
?>
</div>

Howard
 
how are you setting the session variables?
 
Sounds like there is some output before you call the include.

Like with headers, there can be no ouput to screen before calling session_start();

Make sure there no text or html before you call session_start();

Even a blank line would cause this error.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for your help. This has help me to learn a lot.
I had an echo and I redirted prior to setting my session variables.

Howard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top