PHP Redirect url

Newbie here!
I want to use a form in which you select a location and the type of information you would like to view. It takes you to a subdomain like blah.mysite.com/option1.php option1.php being the the type of information the person selected. This is what I have:

<form method="post" action="jump.php"> <table width="100%" border="0"> <tr> <td colspan="3"><div align="center"><span class="whatareyou">What Are You Looking For?</span></div></td> </tr> <tr> <td width="33%"><div align="center" class="whatareyou"> <input type="radio" name="radio" id="type" value="option1.php"> <label for="type"></label>option 1</div></td> <td width="33%"><div align="center" class="whatareyou"> <input type="radio" name="radio" id="type" value="option2.php"> <label for="type"></label>option 2</div></td> <td width="33%"><div align="center" class="whatareyou"> <input type="radio" name="radio" id="type" value="option3.php"> <label for="type"></label>option 3</div></td> </tr> <tr> <td colspan="3">&nbsp;</td> </tr> <tr> <td colspan="3"><div align="center" class="whatareyou">Where Are You Looking?</div></td> </tr> <tr> <td colspan="3"><div align="center"> <select name="url" id="url" style="font-size:24px"> <option value="http://blah.mysite.co/" selected>blah</option> <option value="http://blahblah.mysite.co/" selected>blahblah</option> <option value="http://blahblahblah.mysite.co/" selected>blahblahblah</option> </select> <input name="button" type="submit" class="button_login" id="button" value="Search"> <br> </div></td> </tr> </table> </form>

This is what I’m having trouble with:

[php]<?php
session_start();
$url = $_POST[“url”];
$type = $_POST[“type”];

$parsedUrl = $url.’/’.$type;
header(“Location: $parsedUrl”);
?>[/php]
Am I using $parsedurl incorrectly?
Thanks

[php]

<?php session_start(); $url = $_POST["url"]; $type = $_POST["type"]; $parsedUrl = $url . "/" . $type; header('Location: ' . $parsedUrl); ?>

[/php]

Like this.

Thanks for the helpbut now I’m getting this error:

Forbidden

You don’t have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Okey, let me know what the address is that you want to redirect too. Let me know how you want the adress to look like, and how the options in your form look like.

Basically I want the user to select a location like if they choose the first one blah and then the type of information they seek so they select I would lke the jump.php file to jump them to http://blah.mysite.co/option1.php that’s exactly I would like url to show just like that too.

Thanks

okey got it.

Its like this now: $parsedUrl = $url . “/” . $type;

That makes it // so do like this: $parsedUrl = $url . $type;

since you already have .co/ in the end of all your options.

What url dose it give you now? and what url did it give you from the last try when you got the 404

This
[php]$parsedUrl = $url.’/’.$type;[/php]
Should be this
[php]$parsedUrl = $url.$type;[/php]
Because you are already adding the / in the url of the form value. Also just so you know, this is highly un-secure and not a good way to do what you are doing without additional sanitizing of the posted info.

Thank you both unkn and fastsol
I’ve changed it bot but I’m still getting this 404 error
Forbidden

You don’t have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


Apache Server at newyork.bigappleapartments.co Port 80

I’m thinking it is an .htaccess error on godaddy which I can’t even find the file on the server.

Ok do this and post back what you see on the screen
[php]

<?php session_start(); echo $url = $_POST["url"]; echo '
'; echo $type = $_POST["type"]; echo '
'.$parsedUrl = $url.'/'.$type; //header("Location: $parsedUrl"); ?>

[/php]

http://www.mysite.co/blah/

http://www.mysite.co/blah//

I don’t see the sub domain at all just folder it gets redirect to but not http://blah.mysite.co

You have the names of the radio set as radio and not type

name="radio"

Should be this

name="type"

type=“radio” name=“radio” id=“type”

you have to call the correct POST, you should put name to type.

WOW I feel like a complete idiot ;D

THANK YOU SO MUCH TO BOTH!

Incredible

Sponsor our Newsletter | Privacy Policy | Terms of Service