Forum Moderators: coopster

Message Too Old, No Replies

Header (Location".problem")

Will not redirect user to targeted page..

         

Senmar50

3:24 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Hi All,

My page does everything I want it to do, but, redirect the user to the page I list in the "header". Can someone tell me if the "Header" is in the right place. I know the header has to come before any output to the browser(echo, print..etc). Help...smile

Thanks In Advance
Senmar
^^^^^^^^^^^^^^^^^^^

<?php
$page_title = "Register";
if (isset($_POST['submit'])) { // Handle the form.

// Create a function for escaping the data.function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.

$message = NULL; // Create an empty new variable.

// Check for a username.
if (empty($_POST['username'])) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = $_POST['username'];
}

//Check for a first name.
if (empty($_POST['first_name'])) {
$fn = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
} else {
$fn = $_POST['first_name'];
}

// Check for a last name.
if (empty($_POST['last_name'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter your last name!</p>';
} else {
$ln = $_POST['last_name'];
}

// Check for an email address.
if (empty($_POST['email'])) {
$e = FALSE;
$message .= '<p>You forgot to enter your email address!</p>';
} else {
$e = $_POST['email'];
}

// Check for a password and match against the confirmed password.
if (empty($_POST['password1'])) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
if ($_POST['password1'] == $_POST['password2']) {
$p = $_POST['password1'];
} else {
$p = FALSE;
$message .= '<p>Your password did not match the confirmed password!</p>';
}
}

if ($u && $fn && $ln && $e && $p) {

// If everything's OK.

// Register the user in the database.
require_once (''); // Connect to the db.

// Make the query.
$query = "INSERT INTO people (username, first_name, last_name, email, password, registration_date) VALUES ('$u', '$fn', '$ln', '$e', MD5('$p'), NOW() )";
$result = mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.

// Send an email, if desired.

$body = "Thank you for registering with our!\n\nYour username is '{$_POST['username']}' and your password is '{$_POST['password1']}'.\n\nSincerely,\n\nWebSite Coordinator";
mail ($_POST['email'], 'Thank you for registering!', $body, 'From: senamo@aol.com');

header ("Location: login.php");

echo '<p>You are now registered. An email has been sent to your email address confirming the information.</p>';
exit(); // Quit the script.

} else {
$message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
}
} else {
mysql_close(); // Close the database connection.

$message .= '<p>Please try again.</p>';

}

} // End of the main Submit conditional.

// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}

?>

<html>
<head>
<title></title>

</head>
<body>
<div id="header">
<h2>Welcome</h2>
<h4>DECEMBER 10-12, 2005</h4>

<h4> To access the important documents in this database, please register below.</h4>
</div>

<div id="container">

<div id="left">
<div class="form">
<form method="POST" action="welcome.php">
<tr>

<td><b>Enter Username:</b> <input type="text" name="username" size="20"></td>
<br/>
<td><b>Enter Password:</b> <input type="password" name="password" size="20"></td>
<br/>
<td><input type="submit" value="Submit"></td>

<td><input type="reset"></td>
</tr>
</form>
</div>

<div class="button"><a href="index.htm">BACK TO HOME PAGE</a>
</div></div>
<div id="content">

<p><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset><legend><b>Please register below to gain access to the ""</b></legend>

<p><b>User Name:</b> <input type="text" name="username" size="20" maxlength="25" value="<?php if (isset($_POST['username'])) echo $_POST['username'];?>" /></p>

<p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="25" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name'];?>" /></p>

<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name'];?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>" /> </p>

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="32" /></p>

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
</p>
<div align="center"><input type="submit" name="submit" value="Register" /></div>

</form>

</div>
</div>
<div id="footer">
<p>&copy 2005 by ME</p>
</div>
</body>
</html>

jatar_k

3:37 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



can you explain what actually happens?

do you get a blank page?
is there an error of some kind?

Angelis

3:47 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Could be something as simple as using [...........] in the header

header ("Location: http://www.example.com/file.ext");

Senmar50

3:54 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Hi,

After the email is sent to tell the user that he/she is registered, I want to redirect them to the login page. There they can login to the members'section with their new password. The browser seems to stay on the email message sent to the new member, and doesn't redirect to the "Login/Logon" page...

Thanks,
Senmar

jatar_k

4:05 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the first thing that comes to mind is the path as Angelis mentioned

header ("Location: login.php");

that would mean that login.php is in the same directory as the script that is being executed. Is this the case?

Senmar50

4:06 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Thanks Guys!

You always come through...

Use the "Absolute Header:
header ("Location: [mysite.org...]

Thanks Again,
SenMar

Senmar50

4:11 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Hi Again,

Do I always have to use the "absolute header"?
The "login.php" is in the same location as the other files. I'm just testing them...

Thanks,
SenMar

jatar_k

4:46 pm on Oct 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you shouldn't have to, I almost never do

Angelis

7:53 am on Oct 26, 2005 (gmt 0)

10+ Year Member



If it works.... Dont break it.... :)

Netter

9:19 am on Oct 26, 2005 (gmt 0)

10+ Year Member



didn't have time for reading it all.

simple question: does your Header() go BEFORE ANY text into browser?

because if you first show the message like "Congratulations! You are registered user now!" and then somewhere Header(); it will not work.

loki_racer

12:41 pm on Oct 26, 2005 (gmt 0)

10+ Year Member



Yes,

IE craps out if header() is sent to the browser after any display code has been sent to it. Therefore, to get header() to work properly across browsers, you must sent header() to the client side before anything else.

mcibor

10:15 am on Oct 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try putting
error_reporting(E_ALL);

and see if there are any mistakes.

Maybe the problem is with sending the email? Especially if $_POST['email'] is not set!

Best regards
Michal Cibor

gsnider

4:24 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



header ("Location: login.php");

echo '<p>You are now registered. An email has been sent to your email address confirming the information.</p>';
exit(); // Quit the script.

take out that echo line. and the absolute header crap that you seem to think works. that's a backdoor in programming.