Re: Session problem

From: Date: Tue, 18 Mar 2003 09:32:22 +0000
Subject: Re: Session problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-140091@lists.php.net to get a copy of this message
Do not echo $query or any output before session_start(); or session_register("xxx"); (mean headers) //echo $query Or may be you can put ob_start(); before first output and put ob_end_flush(); after last headers ob_start(); echo $query . . //your code. . . session_register("ses_level"); ob_end_flush(); Hope this helps! "Shaun" <shaun@mania.plus.com> wrote in message news:20030317223230.18186.qmail@pb1.pair.com... > Hi, > > I get the following error when using using the following script to > authenticate a user. The login form is inside a frameset, is this whats > causing th eproblem, and is there a way round this? > > Warning: Cannot send session cookie - headers already sent by (output > started at /home/w/o/workmanagement/public_html/authenticate_user.php:12) in > /home/w/o/workmanagement/public_html/authenticate_user.php on line 35 > > authenticate_user.php: > <?php > require("dbconnect.php"); > > // Assume user is not authenticated > $auth = false; > > // Formulate the query > $query = "SELECT * FROM WMS_User WHERE > User_Username = '$_POST[username]' AND > User_Password = '$_POST[password]'"; > > echo $query; > > // Execute the query and put results in $result > $result = mysql_query( $query ) > or die ( 'Unable to execute query.' ); > > // Get number of rows in $result. > $num = mysql_numrows( $result ); > > if ( $num != 0 ) { > > // A matching row was found - the user is authenticated. > $auth = true; > > //get the data for the session variables > $suser_name = mysql_result($result, 0, "User_Name"); > $suser_password = mysql_result($result, 0, "User_Password"); > $stype_level = mysql_result($result, 0, "User_Type"); > > $ses_name = $suser_name; > $ses_pass = $suser_password; > $ses_level = $stype_level; > > session_register("ses_name"); //this is line 35 > session_register("ses_pass"); > session_register("ses_level"); > } > > //if user isn't authenticated redirect to appropriate page > if ( ! $auth ) { > include("login.php"); > exit; > } > > //if user is authenticated, include the main menu > else{ > include("home.php"); > } > > //close connection > mysql_close(); > ?> > > Thanks in as=dvance for your help > >

« previous php.general (#140091) next »