English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories


this is just a header location test










$first = $_POST["first"];
if( $first != null )
{
if( $first == "abin")
{
header ("Location: http://www.yahoo.com/");
//echo $first;
exit;
}
}
?>

the problem with this code is that ..it doesn't load yahoo.com page even if I write "abin" in the input box...

is there any problem with the header( ) function...
help me please...abin

2007-04-01 12:39:30 · 5 answers · asked by abinawale 2 in Computers & Internet Programming & Design

5 answers

You can't use header() to send headers to a page if the headers have already been sent, which is exactly what you have done by placing your call to header() after the HTML elements in the page.

Also, in PHP, associative array element names are delimited with single-quotes, not double-quotes.

$first = $_POST['first'];
if( $first != null )
{
if( $first == "abin")
{
header ("Location: http://www.yahoo.com/");
exit;
}
}
?>

this is just a header location test








UPDATE:

You don't need to give the form an action. Null actions automatically post back to the same page.

You also don't need to check for whether the form has been submitted. If there's no form submission, the $_FORM superglobal won't be populated.

You also don't need an else statement. If the page sends a header to the page specifying a different location, the redirection makes all remaining page execution moot; the end user never sees it.

In fact, that's why you follow the header() with exit; to cease all further execution of code on the page, so you're not wasting resources by executing code that will never be seen.

2007-04-01 13:14:29 · answer #1 · answered by Anonymous · 1 0

To extend dhvrm's answer, give the form an action.. in the case below, this page submits to itself. Also, since it is self submitting, it would probably be a good idea to check first if the form has been submitted before loading variables and/or displaying the form.

//check to see if post is submitted
if (isset($_POST['first'])) {

$first = $_POST['first'];
if( $first != null )
{
if( $first == "abin")
{
header ("Location: http://www.yahoo.com/");
exit;
}
}
}
else {
?>

this is just a header location test







//close the else statement
}
?>

2007-04-01 13:28:01 · answer #2 · answered by Jen 2 · 0 1

Put the following in some different file.
$first = $_POST["first"];
if( $first != null )
{
if( $first == "abin")
{
header ("Location: http://www.yahoo.com/");
//echo $first;
exit;
}
}
?>
and add action attribute to form tag. like
action="name of the file which contains above php code"
And make sure the method attribute of form is set to POST.

2007-04-02 01:31:55 · answer #3 · answered by Atif Majid 3 · 0 0

Make sure to set the action of your form.

2007-04-01 12:56:15 · answer #4 · answered by kethinov 2 · 0 2

@Jen
your line...


should actually be...

2007-04-02 13:06:15 · answer #5 · answered by my_screen_name 2 · 0 0

fedest.com, questions and answers