Jump to content

Header Error (yes I have read the sticky)


Nodral

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/238554-header-error-yes-i-have-read-the-sticky/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.