lbaxterl Posted March 29, 2009 Share Posted March 29, 2009 Im creating a login form but everytime i try to output a header or start a session i get errors: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /web/users/e5034824/Test/confirmlogin.php:1) in /web/users/e5034824/Test/confirmlogin.php on line 2 <?php session_start(); $username = $_POST['myusername']; $password = $_POST['mypassword']; require 'common.php'; $q = "SELECT id FROM members WHERE username = '$username' AND password = '$password'"; $result = $mysqli->query($q) or die(mysqli_error()); if (mysqli_num_rows($result) == 1) { $user = $result->fetch_array(MYSQLI_NUM); $_SESSION['admin'] = $user[0]; // Sets the session to the user's ID } else { $message = "User Name Not Recongised, Please Try Again!"; echo $message . ' <meta HTTP-EQUIV="refresh" content=5;url="login.php"/>'; } ?> I always get the header error message but have no clue on how to fix it any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/ Share on other sites More sharing options...
MadTechie Posted March 29, 2009 Share Posted March 29, 2009 Read this the problem with the code below is the white space at the start.. either that or your including it from another file that has output! // <---- remove this white space ---> <?php session_start(); $username = $_POST['myusername']; Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/#findComment-796043 Share on other sites More sharing options...
Salkcin Posted March 29, 2009 Share Posted March 29, 2009 yes, any output to the browser before using headers will cause errors. Remember that header() must be called before any actual output is sent' date=' either by normal HTML tags, blank lines in a file, or from PHP. [b']It is a very common error[/b] to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/#findComment-796047 Share on other sites More sharing options...
lbaxterl Posted March 29, 2009 Author Share Posted March 29, 2009 sorry there was no white space i double taped enter before posting the code stupidly sorry, any other ideas could it be a server issue? Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/#findComment-796053 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2009 Share Posted March 29, 2009 http://www.phpfreaks.com/forums/index.php/topic,243246.msg1135754.html#msg1135754 Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/#findComment-796055 Share on other sites More sharing options...
lbaxterl Posted March 29, 2009 Author Share Posted March 29, 2009 thank you so much need to save as ansi files, is there a easy way to convert them all in dreamweaver? Quote Link to comment https://forums.phpfreaks.com/topic/151567-solved-headers-driving-me-mad-please-help/#findComment-796061 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.