开发者

Entering HTML form data in PHP code?

There is a textbox (name="url") in a form which contains a page URL. When the form is submitted, data will be sent to a PHP page. I want to know how to redirect that PHP page to the URL from the 开发者_高级运维form? I have the code for redirection:

header( 'Location: www.google.com' );

Now I want to know how use that URL from the form, like so:

header( 'Location: << here should be the url we got from form >>' );

How could I do this?


Just use string concatenation...

header('Location: ' . $_POST['url']);
exit;

I am pretty sure header() doesn't allow \n or anything that would allow additional headers to be set. If it did, it would be HTTP splitting, and that is bad.

Also, make sure you exit. User agents can ignore your Location header if they want. The WayBackMachine bot also has a habit of ignoring Location headers.

This does violate some recommendation (can't remember which right now) though that says user input should not be placed in a Location header. But so long as you don't allow \n, you should be OK. :)


Can't you just do this:

header("Location: {$_POST['url']}\r\n");

? Edit: Sorry for the really late response, should have checked.

Edit 2: If you want to redirect after twenty seconds, add this in the <head> section:

<meta http-equiv="refresh" content="20; <?php echo $_POST['url']; ?>" />

And make sure to include a link back to the page somewhere in your body for accessibility:

<a href="<?php echo $_POST['url']; ?>">Go back</a>


header('Location: '.$_POST['url']);


Can't you simply concatenate the value passed by the post with the location string to redirect? Or am I not understanding the problem correctly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜