Jump to content


Photo

need help with session_start()


  • Please log in to reply
6 replies to this topic

#1 zxiny_chin

zxiny_chin
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 April 2006 - 11:13 AM

login.php

include("check_session.php");
include_once("connectDB.php");
global $aut_user;

mainpage.php

session_start();
$username=$_SESSION[ 'AUTH_USER' ];


a warning msg shown:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\xampp\htdocs\FYP06\member_main.php:5) in C:\Program Files\xampp\htdocs\FYP06\member_main.php on line 15

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\xampp\htdocs\FYP06\member_main.php:5) in C:\Program Files\xampp\htdocs\FYP06\member_main.php on line 15

can somebody help me out...i m in an urgent stage...thx ya

u can add mine yahoo messenger...
ID : inger_wong

thx

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 25 April 2006 - 11:22 AM

You somewhere sent something to the browser, you wrote something. It could be a <html> tag at the top of the page, or just a white space you have by mistake. Put the seession_start() at the very top of the page.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 zxiny_chin

zxiny_chin
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 April 2006 - 11:26 AM

you mean put session start before <?php ?

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 25 April 2006 - 11:33 AM

No, I mean:
<?php session_start(); ?>

...
all the rest here....

But if you need to do something before you call the session_start(), make sure nothing is being echo'd or normaly written with html. Once I went nuts because one of my included files had a white space after the ending "?>" and I got the same error when I tried to send a cookie.

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 zxiny_chin

zxiny_chin
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 April 2006 - 11:42 AM

actually my code go like this...

<?php
include("check_session.php");
include_once("connectDB.php");


extract( $_POST );
$query = "SELECT * FROM employee WHERE E_NAME = '$user' and E_PASSWORD = '$pword'";
$result = mysql_query( $query ) or die( 'Could not execute SQL query!' );
$row = mysql_fetch_array( $result );

if ( $row )
{
session_start();
global $_SESSION;
$_SESSION[ 'AUTH_USER' ] = $user;


$setnow = date( "Y-m-d H:i:s" );
$updateQuery = "UPDATE employee SET last_login = '$setnow' WHERE E_NAME = '$user'";

mysql_query( $updateQuery );

print ("Hi, $user <br> ");
print("<html><head><meta http-equiv=\"REFRESH\" content=\"1; url=member_main.php\"</head>
<body>Directing...</body></html>");
sleep(2);

}

else
{

print("<html><head><meta http-equiv=\"REFRESH\" content=\"1; url=login.html\"</head>
<body>
<p>Invalid User Name and Password!</p>
<p>Please try again!!!</p>
<p>Redirecting to Login Page...</p>
</body>
</html>");
sleep(3);}

?>









the main page


<body>
<?php

session_start();
$username=$_SESSION[ 'AUTH_USER' ];

//include_once("secure_page.php");
/*if (isset($_SESSION))
echo("session oled started");
else
session_start();
*/


// Connect to MySQL
include_once("connectDB.php");
//$username=$_REQUEST['$user'];
echo ("Hi,". $username." <br>");
$dateInfo = date("d-m-Y");
print("$dateInfo");

print("<table width=\"100%\" border=\"0\" align=\"left\" cellpadding=\"1\" cellspacing=\"0\">\n");
print("<tr>&nbsp;</tr>\n");
print("<tr>\n");
print("<th scope=\"row\"><div align=\"left\"><b>Today Delivery Schedule : </b></div></th>");
print("</tr>\n");
print("<tr>\n");
print("<th scope=\"row\"><div align=\"left\">Under Construction</div></th>");
print("</tr></table>\n");
/*$result = mysql_query("select E_IC from EMPLOYEE where E_NAME='chai'", $database);
for ( $counter = 0;
$row = mysql_fetch_row($result);
$counter++ ){

// build table to display results
print( "<tr>" );

foreach ( $row as $key => $value )
print( "<td>$value</td>" );

print( "</tr>" );
}


} */
?>

</body>
</html>


#6 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 25 April 2006 - 01:15 PM

This is your problem:
the main page

<body>
<?php
session_start();
....
You see, you need to delete the <body> tag. You cant have anything sent to the browser (to be written in the source code as html) before setting a cookie, a session, or using the header() function (Maybe there are more stuff that I dont know).
Do something like this:
<?php
session_start(); echo("<body>");

....Rest of code....

Orio.
Think you're smarty?

(Gone until 20 to November)

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 01:38 PM

You don't have to delete the "<body>" tag, just put
<?php session_start() ?>
at the very start of the file.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users