Nodral Posted June 6, 2011 Share Posted June 6, 2011 Hi All I'm getting a header error on the code given and having read the sticky on this forum cannot find where the error is and why my page won't redirect. Any ideas? connect.php <?php $link = mysql_connect('localhost', '****', '********'); if (!$link) { echo'1Unable to connect to the database server.'; exit(); } if (!mysql_set_charset('utf8', $link)) { echo'2Unable to connect to the database server.'; exit(); } if(!mysql_select_db('******', $link)) { echo'3Unable to connect to the database server.'; exit(); } ?> index.php <?php $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); //set variables from login form below if(strlen($_POST['username'])>1){ $username=$_POST['username']; } if(strlen($_POST['password'])>1){ $password=$_POST['password']; } $register=$_POST['register']; $forgotten=$_POST['forgotten']; //log the user in or create an acct for learning styles include_once("connect.php"); ?> <form method="POST" action=""> <p>Username <input type="text" name="username" size="40"></p> <p>Password <input type="password" name="password" size="40"></p> <p><input type="submit" value="Login"> <p>If you have not previously completed this questionnaire, please click the 'Register' button below, alternatively if you have forgotten your login details please click the 'Forgotten Login' button.</p> <p><input type="submit" name="register" value="Register"> <input type="submit" name="forgotten" value="Forgotten Login"></p> </form> <?php if(isset($username, $password)){ //log user in //include("login.php"); } elseif(isset($register)){ //divert to reg form $extra = 'register.php'; header("Location: http://$host$uri/$extra"); } elseif(isset($forgotten)){ //ask for email address and send mail of details //include("forgotten"); } elseif((isset($username) and !isset($password)) or (!isset($username) and isset($password))){ //give message of details req echo "no details"; } ?> Error -Warning: Cannot modify header information - headers already sent by (output started at D:\Documents\AI24\Web\skooch\learning_styles\index.php:26) in D:\Documents\AI24\Web\skooch\learning_styles\index.php on line 40 Any ideas anyone? Quote Link to comment https://forums.phpfreaks.com/topic/238554-header-error-yes-i-have-read-the-sticky/ Share on other sites More sharing options...
KevinM1 Posted June 6, 2011 Share Posted June 6, 2011 Like the sticky says, you can't have any output sent to the browser before attempting to send a header. Your form is output. You need to redesign your page. As a hint, well-formed PHP pages do all of their processing first, then show output. Quote Link to comment https://forums.phpfreaks.com/topic/238554-header-error-yes-i-have-read-the-sticky/#findComment-1225851 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 nightslyr is right, for an informative post, there are a few other things that can cause this error. 1. white space outside of the php start and end tags. 2. extra characters outside of the php start and end tags. 3. try changing output_buffering=on in php.ini Quote Link to comment https://forums.phpfreaks.com/topic/238554-header-error-yes-i-have-read-the-sticky/#findComment-1225854 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.