$ _GET不传递包含'#'值的结果

时间:2017-10-29 16:04:57

标签: php html

我传递的值为:http://example.com/channel.php?channel=#football

注意:#football是一个#标签,#用作对标签的引用 但是在channel.php页面上,'#football'的值没有使用下面的代码。

<?
if (isset($_GET['channel']) && $_GET['channel'] != "") {
    $channel = $_GET['channel'];
}
?>

1 个答案:

答案 0 :(得分:0)

URI的#符号ends the request part and starts the hash part,它不会发送到服务器。在处理请求之前,使用encodeURIComponent对哈希进行编码并将其解码回后端。所以你的URI应该是这样的:

"http://example.com/channel.php?channel="+encodeURIComponent("#football")
// gives
"http://example.com/channel.php?channel=%23football"