URL Redirect problem
I am using the following php which takes values from a form, once the values have been submitted into the database it takes the $_POST[url] and uses it to redirect the user to the next page, but this does not work.
The url in the address bar is as follows and it dispalys "page cannot be found"
Address bar: http://www.website.co.uk/www.google.com
Whereas,
When the user clicks on a link the address bar will display:
http://www.website.co.uk/click%20this
Why won't it redirect to the url when using $_POST? How can I make it redirect?
pr0gr4mm3r posted this at 18:24 — 5th August 2007.
He has: 1,502 posts
Joined: Sep 2006
If you are going to redirect the user to an absolute location (ie google.com instead of something.php at your website), be sure you are including the full URL including 'http://'. I'm guessing that you did...
<?php
header('Location: ' . $_POST['url'])
?>
...where $_POST['url'] = 'www.google.com'. Since, you did not include the full URL, it took it as a relative URL and added it to the current location of your working directory (where your form file is located), which was 'http://www.website.co.uk/'.
Also, check out PHP's documentation for the header() function.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.