Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/
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.
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>
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.