1

I have a form that points to a php file. all the php file does is redirects the user to a specific page. I cannot seem to get it to work and im not sure what i am doing wrong.

<form method="post" action="processRegister.php">
    User Name: <input type="text" name="userName" maxlength="32"><br>
    Password: <input type="password" name="userPassword" maxlength="32"><br>
    <input type="submit">
</form>

processRegister.php

<?php
// processRegister.php
//////////////////////
header("Location: http://www.google.com/");
/*
// First include the class definition
include('UserClass.php');

// Next, create an instance of the class
$newUser = new User;

// Call the registerUser() method, passing in the required variables
if ($newUser->registerUser($userName, $userPassword)) {
  header('Location: www.google.com');
} 
else {
  header('Location: www.yahoo.com');
}
*/
?> 
user1082764
  • 1,973
  • 9
  • 26
  • 40

4 Answers4

4

Use an exit call after using header() to change locations. This will not only prevent unnecessary processing, but it also prevents potential security holes, as if you don't exit after changing locations, the page is processed and sent to the browser as per normal. In cases where you're, for example, redirecting unauthorized users to a login page, the sensitive content will still be sent to them, and they can capture it.

FtDRbwLXw6
  • 27,774
  • 13
  • 70
  • 107
0

Ah, I read your post too quickly, and didn't realize it was on two different pages. My fix is a not going to fix yours.

Try this though, but a flag after the header. So instead of just

header("Location: http://www.google.com/");

make it

header("Location: http://www.google.com/");
echo "Flag1"; 

If it doesn't even print "Flag1," than we'll have a better understanding of why it isn't working.

Anthony Tantillo
  • 300
  • 1
  • 3
  • 12
  • why is it obvious that there is output? – user1082764 Jan 17 '12 at 19:05
  • it doesnt even print Flag1. i think it is something outside my short script tho because i test it out on a test site i have and it works just fine. i cant seem to find the problem tho – user1082764 Jan 17 '12 at 19:48
  • Perhaps putting an [echo "flag0";] before the header would tell you if it's even getting to that page. If it doesn't even print "flag0" you know that there's something wrong on the previous page. Can you upload the entirety of the page on PasteBin that links to processRegister.php? I just copied both code verbatim, ran it on my server, and it worked like a charm. I'm sure there is something wrong with the page containing the Form that's preventing the header from working. – Anthony Tantillo Jan 17 '12 at 19:57
0

use exit() after header and on the very top of the page (in php) wright ob_start(); The most important is the o ob_start! this signifies where the code starts.

<?php
ob_start();
// processRegister.php
//////////////////////
header("Location: http://www.google.com/");
/*
// First include the class definition
include('UserClass.php');

// Next, create an instance of the class
$newUser = new User;

// Call the registerUser() method, passing in the required variables
if ($newUser->registerUser($userName, $userPassword)) {
  header('Location: www.google.com');
} 
else {
  header('Location: www.yahoo.com');
}
*/
exit();
?> 
faq
  • 2,965
  • 5
  • 27
  • 35
0

Does you source file has good encoding? If it is just UTF-8, you need to change it to UTF-8 without BOM, because BOM can causes the problem.

terenaa
  • 540
  • 5
  • 15