simple php meta redirect script not working
I have http://mysite.com/go.php?site=http://somesite.com/main/?s=12&action=load
<?php
$url 开发者_如何学编程= $_GET['site'];
echo "<meta http-equiv=\"refresh\" content=\"0;url=" . $url . "\">";
however, it takes me to http://somesite.com/main/?s=12
which fails to load.
how to make it go to http://somesite.com/main/?s=12&action=load
You need to urlencode()
the URL you pass as the site
variable beforehand (i.e. when creating the go.php link).
As a side note, if this is the only thing your page outputs, why not use
header("Location: ".$url);
?
It would issue a 302 Found
header to the browser, telling it to follow to the new location, instead of outputting HTML (which is broken anyway if output without a proper page structure).
[EDIT]: New Solution
This works like a charm. I tested on my machine.
$url = urldecode(substr(http_build_query($_GET),5));
echo "<meta http-equiv=\"refresh\" content=\"0;url=" . $url . "\">";
Old solution (not working)
Change your code to this:
$url = $_GET['site'];
echo "<meta http-equiv=\"refresh\" content=\"0;url=" . urlencode($url) . "\">";
You need to encode the parameter you are passing to the site
parameter. You can do so by using urlencode()
in PHP or encodeURI()
in javascript.
So that makes it something like:
http://mysite.com/go.php?site=http%3a%2f%2fsomesite.com%2fmain%2f%3fs%3d12%26action%3dload
Now in PHP, you can do:
<?php
header("Location: ".$_GET['site']);
?>
精彩评论