zxiny_chin Posted April 25, 2006 Share Posted April 25, 2006 [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 15Warning: 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 15can somebody help me out...i m in an urgent stage...thx yau can add mine yahoo messenger...ID : inger_wongthx Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/ Share on other sites More sharing options...
Orio Posted April 25, 2006 Share Posted April 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30489 Share on other sites More sharing options...
zxiny_chin Posted April 25, 2006 Author Share Posted April 25, 2006 you mean put session start before <?php ? Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30491 Share on other sites More sharing options...
Orio Posted April 25, 2006 Share Posted April 25, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30493 Share on other sites More sharing options...
zxiny_chin Posted April 25, 2006 Author Share Posted April 25, 2006 actually my code go like this...<?phpinclude("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><?phpsession_start();$username=$_SESSION[ 'AUTH_USER' ]; //include_once("secure_page.php");/*if (isset($_SESSION))echo("session oled started");elsesession_start();*/// Connect to MySQLinclude_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> </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> Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30498 Share on other sites More sharing options...
Orio Posted April 25, 2006 Share Posted April 25, 2006 This is your problem:[code]the main page<body><?phpsession_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]<?phpsession_start(); echo("<body>");....Rest of code....[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30526 Share on other sites More sharing options...
kenrbnsn Posted April 25, 2006 Share Posted April 25, 2006 You don't have to delete the "<body>" tag, just put[code]<?php session_start() ?>[/code] at the very start of the file.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8354-need-help-with-session_start/#findComment-30537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.