Session id problem

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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Session id problem

Post by ianhull »

Hi again,

I am trying to start a session using this code but I get a error when opening the page.
Can anyone please help?

Thanks

Code: Select all

<!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>
<title><?php echo $firstname ?> from <?php echo $companyname?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
body,td,th {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #333333;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style6 {
	font-size: 24px;
	color: #999999;
}
.style7 {font-size: 24px}
.style9 {
	color: #333333;
	font-size: 12px;
}
-->
</style></head>

<body>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th width="2%" rowspan="9" scope="col">&nbsp;</th>
    <th height="29" colspan="3" scope="col"><div align="left" class="style7"></div>      
      <div align="left" class="style6"> &nbsp;<?php echo $companyname ?></div></th>
    <th width="17%" rowspan="9" scope="col">&nbsp;</th>
  </tr>
  <tr>
    <td height="27" colspan="2"><div align="right"><span class="style7"><span class="style7"></span></span></div>      <div align="left"><span class="style7"><span class="style7">&nbsp;<?php echo $jobtitle ?></span></span></div></td>
    <td width="43%" class="style9"><div align="left"><span class="style7"><span class="style9"><?php echo $firstname ?>, you are currently logged in as 
<?php echo $username ?></span></span></div></td>
  </tr>
  <tr>
    <td colspan="2"><div align="left">&nbsp;</div></td>
    <td class="style9"><div align="left">Your login time and date is <?php
echo date("l dS of F Y h:i:s A");
?> 
    </div></td>
  </tr>
  <tr>
    <td colspan="2"><div align="left">&nbsp;&nbsp;Welcome <?php echo $firstname ?>&nbsp;
<?php echo $lastname?>.</div></td>
    <td><div align="left">This information will be logged into the system for security purposes. </div></td>
  </tr>
  <tr>
    <td colspan="2"><div align="left">&nbsp;&nbsp;What would you like to do during this session? </div></td>
    <td><div align="left"></div></td>
  </tr>
  <tr>
    <td height="15" colspan="2" valign="top"><div align="left">&nbsp;&nbsp;
      </div>      <div align="left"></div>            <div align="left"></div></td>
    <td><div align="left"></div>      <div align="left"></div>      <div align="left"></div></td>
  </tr>
  <tr>
    <td width="7%" height="42" valign="middle">&nbsp; &nbsp;
      <span class="style9"><a href="http://www.vrconsult.co.uk"><img src="icons/home.jpg" width="28" height="28" border="0" /></a></span>        <div align="left"></div></td>
    <td width="31%" valign="middle"><span class="style9">Back to Website </span></td>
    <td><div align="left"><?php session_start(); ?>
</div></td>
  </tr>
  <tr>
    <td height="40" valign="middle">&nbsp;&nbsp;&nbsp;
      <a href="add_report.php?username=<?php echo $username?>&ulevel=<?php echo $ulevel?>  "><img src="icons/add.jpg" width="28" height="28" border="0" /></a>        <div align="left"></div></td>
    <td>Add a new report </td>
    <td><div align="left"></div></td>
  </tr>
  <tr>
    <td><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="icons/letter.jpg" width="28" height="28" /></div></td>
    <td>View a report </td>
    <td><div align="left"></div></td>
  </tr>
  <tr>
    <th scope="col">&nbsp;</th>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <th scope="col">&nbsp;</th>
  </tr>
  <tr>
    <th scope="col">&nbsp;</th>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <th scope="col">&nbsp;</th>
  </tr>
  <tr>
    <th scope="col">&nbsp;</th>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <th scope="col">&nbsp;</th>
  </tr>
  <tr>
    <th scope="col">&nbsp;</th>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <th scope="col">&nbsp;</th>
  </tr>
</table>
</body>
</html>
Error is:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Xeneo\vr\admin\index.php:19) in C:\Xeneo\vr\admin\admincontent.php on line 69


And


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Xeneo\vr\admin\index.php:19) in C:\Xeneo\vr\admin\admincontent.php on line 69
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

You have to use session_start() before you've generated any output.

Move the session_start() to the very top of the script. (Even before the <!DOCTYPE)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

additional information: viewtopic.php?t=1157
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

feyd wrote:additional information: viewtopic.php?t=1157
Any chance we can get all the entity references cleaned up in that reference? all the > &quote; probably maakes it hard for the people who need help to understand it....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's on McGruff's list, I believe... but I'll see what I can do..
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thanks but I already tried placing it at the top and I get the same error.

I have check my php ini to make sure the temp folder is available and that is fine. it seems to create the temp session files in there but this is even when I do not start a session using php. not sure if this should happen.

All I really want to do is show the session id on my page somewhere.

is there another way of doing this?

thanks.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Which file did you show us? The error message is referencing two different files:

index.php and admincontent.php

I'm assuming you showed us admincontent.php. The error is telling you that line 19 of index.php is already sending output.

So I would assume you have index.php include admincontent.php? If that's the case, you have to have index.php call session_start() at the top of it, or ensure that index.php doesn't generate any output before including the current file.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Yes your right,

I have now placed the session_start(); at the top of my index.php and I am not getting any errors.
I am though trying to echo the session id onto my page but I am unsure on how to do this.

can you help?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

echo session_id();
:?:
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thankyou both for your help.

Very much appreciated.
Post Reply