php - 如果存在#,则 URL 被修剪

标签 php

我读过这个:What does /#!/ mean in URL?所以我知道 # 是一个片段分隔符,但我在 $_GET 将 URL 显示在后续页面上时遇到了困难,其中存在 #。

我有一个 php 页面,它将用户输入和 URL 发送到显示它的另一个页面。

<?php echo $_GET["url"]; ?>

包含变量的 url 看起来像这样......

http://website.com/qr/index.php?url=http://www.example.com&many=false&set=false

http://www.example.com显示。

而包含这样的片段的 url...

http://website.com/qr/index.php?url=http://www.example.com/#fragment&many=false&set=false

什么都不显示。

我无法使用 $_POST。

感谢您的帮助。

最佳答案

你可能应该 URL encode您放置在 URL 中的参数,特别是因为它也是一个 URL(这意味着它很可能包含在 URL 上下文中具有特殊含义的字符,例如 #/)。如果您使用 Javascript 将 URL 参数放入其中,您可以使用 encodeURIComponent 执行此操作.如果您使用 PHP 添加该 URL 参数,则为 urlencode

从第一个链接开始,井号属于“不安全字符”类别,该类别从作者那里获得了进一步的建议(强调我的):

Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.

“不安全”名称来自 RFC 1738其中有关于英镑字符的具体说明(再次强调我的):

All unsafe characters must always be encoded within a URL. For example, the character "#" must be encoded within URLs even in systems that do not normally deal with fragment or anchor identifiers, so that if the URL is copied into another system that does use them, it will not be necessary to change the URL encoding.

关于php - 如果存在#,则 URL 被修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180794/

相关文章:

php - 使用 AWS 开发工具包 PHP 的 DynamoDB 中的保留字

php - Windows Azure SDK for PHP 中列出的容器

php - 各种 Laravel Controller 方法之间的通用逻辑

php - 使用 Subversion 制作 PHP 项目的生产版本

php - 上传图片到服务器时打开流失败

php - 刚刚发现恶意 PHP 代码

php - 删除迁移会导致异常

php - MySql DB Collection 后更改值

javascript - YouTube IFrame API,加载PHP数据并添加播放器控制功能

php - PDO/MySQL 使用 if 语句获取多列