<?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
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