Jump to content

Header(loaction) Not Working? Help Please


spires

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\" /]
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.