optiplex Posted July 24, 2009 Share Posted July 24, 2009 hi all when i run login-exec.php code, this error will come out Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in Z:\www\algebra\user\login-exec.php on line 66 Warning: Cannot modify header information - headers already sent by (output started at Z:\www\algebra\user\login-exec.php:60) in Z:\www\algebra\user\login-exec.php on line 71 the coding is <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $username = clean($_POST['username']); $password = clean($_POST['password']); //Input Validations if($username == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE username='$username' AND password='".md5($_POST['password'])."'"; $result=mysql_query($qry); echo $qry; //exit; //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); //LINE 66 $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; session_write_close(); header("location: index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); }//LINE 71 }else { die("Query failed"); } ?> Link to comment https://forums.phpfreaks.com/topic/167231-session_regenerate_id/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 24, 2009 Share Posted July 24, 2009 output started at Z:\www\algebra\user\login-exec.php:60 (line 60) You are sending output to the browser on line 60. You cannot send output to the browser as that prevents any more headers from being sent. Link to comment https://forums.phpfreaks.com/topic/167231-session_regenerate_id/#findComment-881737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.