Jump to content

Archived

This topic is now archived and is closed to further replies.

zxiny_chin

need help with session_start()

Recommended Posts

[b]login.php[/b]

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

[b]mainpage.php[/b]

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


[b]a warning msg shown:[/b]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
No, I mean:
[code]<?php session_start(); ?>

...
all the rest here....[/code]

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.

Share this post


Link to post
Share on other sites
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);}

?>








[b]
the main page[/b]

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

Share this post


Link to post
Share on other sites
This is your problem:
[code]the main page

<body>
<?php
session_start();
....[/code]
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:
[code]<?php
session_start(); echo("<body>");

....Rest of code....[/code]

Orio.

Share this post


Link to post
Share on other sites
You don't have to delete the "<body>" tag, just put
[code]<?php session_start() ?>[/code] at the very start of the file.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.