我想显示我传递给此页面的编码网址


I want to display encoded url that I pass to this page

我想在echo的帮助下打印编码的url,例如我发送这样的变量:

"http://www.indiandeal.in/test.php?go=http://www.facebook.com/indiandeal"

如果我传递任何变量但不传递编码的 url 字符串,它工作正常。正常的网址字符串工作正常。

我不想对网址进行编码。我希望这能工作

http://www.indiandeal.in/test.php?go=http%3A%2F%2Fwww.facebook.com%2Findiandeal&123=234

这应该将 URL 打印为

www facebook com indiandeal&123=234

但它只显示

http www facebook com/indiandeal

这是我的代码:

<!DOCTYPE html>
<html>
<body>
<?php
$txt1 = $_GET["go"];
echo $txt1;
?>
</body>
</html>

如果您传递编码的 url,它将自动解码

警告

超全局变量 $_GET 和 $_REQUEST 已经被解码。在 $_GET 或 $_REQUEST 中的元素上使用 urldecode() 可以有意想不到和危险的结果。

如果你仍然想看到它的编码,你可以使用 urlencode()

根据您的评论进行编辑。

如果要保存名为 go 的请求变量的编码版本,您可以这样做

echo urlencode($_GET['go']);  // this encodes it again
//echo urlencode("http://www.facebook.com/indiandeal");

输出

http%3A%2F%2Fwww.facebook.com%2Findiandeal

试试这个它会起作用:

查询字符串可能包含多个key-value对。当有多个键值对时,它们通常用 & 符号分隔(&)

输入:

http://www.indiandeal.in/test.php?go=http%3A%2F%2Fwww.facebook.com%2Findiandeal&123=234

在这里,$_GET["go"]只为您提供与go相关的值。要访问整个查询字符串,您必须使用以下命令:

原始的、未处理的查询字符串可由 QUERY_STRING 服务器变量检索:

echo $_SERVER['QUERY_STRING'];