Jump to content

Archived

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

spires

Header(loaction) Not Working? Help Please

Recommended Posts

Hi, Thanks for reading my post.

I'm quite new to php, and am having a few little problems.

I am building a login system using sessions, and a registration form.

[a href=\"http://www.spirestest.com/login2\" target=\"_blank\"]www.spirestest.com/login2 [/a]

If you register it uploads your details to the data base. (please try out)
(i've add an edit database button, so i know its been uploaded)

but, When you goto login, and enter your details the 'header(Location:home.php);'
Dont seem to work. The details have been passed into session vars, and you can manually type in
the address bar '/home.php' which takes you to the welcome page.
But the header tag wont take you there.

This however works fine on my localhost. i can login and out all day long. Just not on the server.

Any help Please.

Kind regards Jeff

Here is my script.

<?php
include('db.php');

echo '<br>'.date("D, d M Y H:i:s O");
?>

<?php
$arrErrors = array();

if (!empty($_POST['submit'])) {
if ($_POST['username']=='')
$arrErrors['username'] = 'Please fill in your Username.';
if ($_POST['password']=='')
$arrErrors['password'] = 'Please fill in your Password.';


if (count($arrErrors) == 0) {

$username=$_POST['username'];
$password=$_POST['password'];

$sql="SELECT * FROM $db_tbl WHERE username='$username' and PASSWORD='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count==1){
session_register("username");
session_register("password");
header("Location:home.php");
echo "hello";

} else {
$inc_details = '<div class="error">Incorrect login details,<br> Please try again.';
}
}

if (empty($username) || empty($password)) {
$strError = '<div class="error">';
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</div>';
}

}




?>


<html>
<head>
<title>Login</title>
<link href="login.css" rel="stylesheet" type="text/css">
</head>

<body>

<center>
<table width="250px" bgcolor="#EEEEEE" class="TLRB_border">
<tr>
<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<td>
<table width="190px" align="center" bgcolor="#FFFFFF">
<tr>
<td colspan="2">
Members Login</td>
</tr>
<tr>
<td class="loginBox_text">
Username:
</td>
<td>
<input name="username" Type="text" id="username" size="15" value="<?php echo $_POST['username'] ?>">
</td>
</tr>
<tr>
<td class="loginBox_text">
Password:
</td>
<td>
<input name="password" Type="password" id="password" size="15" value="<?php echo $_POST['password'] ?>">
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" value="login">
</td>
</tr>
</table>
</td>
</form>
<tr>
<td>
<center><?php echo $strError; ?></center>
<center><?php echo $inc_details; ?></center>
</td>
</tr>
</tr>
</table>
<a href="index.php" class="loginBox_text">Return to the entrance</a>
</center>

</body>
</html>

Thanks once again [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]

Share this post


Link to post
Share on other sites
You are outputting text/html in your code before you use your header function. You cannot send any output before you use the header function. The following is output:
[code]echo '<br>'.date("D, d M Y H:i:s O");
?>

<?php[/code]

Share this post


Link to post
Share on other sites
Hi, Thanks for your quick reply. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

I have just deleted that line of code, and the ecjo from the include db.php file.
But it still wont let me in.
It seems to bypass the header line of code and go staright to the echo below it.

Any more ideas?

Kind regards
Jeff

Share this post


Link to post
Share on other sites

×

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.