Page 1 of 1

Redirect options list not working

Posted: Mon May 07, 2007 3:05 pm
by leegee3
Again, I am a beginner at php and html so please go easy on me


I have a php file that has the following code...

Code: Select all

<?php

if($location != null)
{
	header("Location:$location");
	exit();
}

?>

<html><head><title> Redirect </title></head>
<body>

Please select a site:

<form action="<?php $PHP_SELF?>" method="post">

<select name="location">

<option value="http://www.google.com"> Google </option>
<option value="http://www.iii.co.uk"> Interactive Investor </option>
<option value="http://www.myspace.com"> Myspace </option>
<option value="http://www.facebook.com"> Facebook </option>

</select>
<input type="submit" name="submit" value="GO">

</form>
</body>
</html>
The page displays all of the options available in a dropdown list but when I click on the go button it does not take me to the appropriate page. Global Registers are turned off if that makes any difference!!
Any ideas???

Thanks Lee

Posted: Mon May 07, 2007 3:08 pm
by guitarlvr
the following line should look like so:

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
However it isn't good practice to use phpself. You can use '#' in place of it. That will redirect php to the current page.

Wayne

Posted: Mon May 07, 2007 3:13 pm
by leegee3
Hi, I just tried your suggestion but it dodnt work.

After clicking on the go button, it just redirects itself to the same page with the dropdown list, which is the same as was happening previously.

Any other suggestions. I wont be able to sleep unless I get this sorted, ha.

Lee

Posted: Mon May 07, 2007 3:24 pm
by guitarlvr
check this out and see if this will work for you:

Code: Select all

<?php

if (isset($_POST['submitted'])){
	$location = $_POST['location'];
		switch ($location)
                        {
			case "http://www.google.com":
				//code for google.com
				break;

			case "http://www.facebook.com":
				//code for facebook.com;
				break;

			case "http://www.myspace.com":
				//code for myspace.com;
				break;

			case "http://www.iii.co.uk":
				//code for iii.co.uk;
				break;
                       {
}else{
?>

<html><head><title> Redirect </title></head>
<body>

Please select a site:

<form action="#" method="post">

<select name="location">

<option value="http://www.google.com"> Google </option>
<option value="http://www.iii.co.uk"> Interactive Investor </option>
<option value="http://www.myspace.com"> Myspace </option>
<option value="http://www.facebook.com"> Facebook </option>

</select>
<input type="submit" name="submit" value="GO">
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
}
?>
</body>
</html>
Something like that

Posted: Tue May 08, 2007 8:15 am
by leegee3
Hey, that PHP code didnt work either. The page redirects, but it goes to a blank page now, and in the url, it places a # at the end of it.

Posted: Tue May 08, 2007 8:52 am
by big_mumma
fyi: I pasted the code you initially provided into a php page, and uploaded it to my server, tested it, and works fine.

Don't think its a coding issue as it worked fine for me...

Re: Redirect options list not working

Posted: Tue May 08, 2007 8:56 am
by Grim...
leegee3 wrote:Global Registers are turned off if that makes any difference!!
You need to add a line to your script

Code: Select all

<?php 
$location = $_POST['location']; // new line
if($location) //an easier way to see if a variable has any content
{ 
        header("Location:$location"); 
        exit(); 
} 

?>