Jump to content


Photo

Header(loaction) Not Working? Help Please


  • Please log in to reply
2 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 28 June 2006 - 07:16 PM

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\" /]
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 28 June 2006 - 07:19 PM

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:
echo '<br>'.date("D, d M Y H:i:s O");
?>

<?php


#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 28 June 2006 - 07:32 PM

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
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users