【问题标题】:Unable to get id starting with # from URL PHP无法从 URL PHP 中获取以 # 开头的 id
【发布时间】:2021-05-28 12:21:13
【问题描述】:

我正在尝试从 URL 中获取 id。

网址:http://localhost/user_notes/user.php?id=1234

echo $_GET['id']; // outputs 1234    

但是如果我在 id 的开头使用# 那么我就没有得到 id。

网址:http://localhost/user_notes/user.php?id=#1234

echo $_GET['id']; // outputs nothing  

【问题讨论】:

  • 请在您的问题中分享您的 htaccess 文件。你能提一下这个# 是怎么来的吗?请务必提及您要访问的网址?
  • 我在 url 中明确包含了 #。 (不要将这个问题与上一个问题联系起来)
  • 好吧,因为你在上一个问题中问过这个问题,所以我很困惑,可能是 php 专家可以参与这个问题。

标签: php url browser


【解决方案1】:

如果你想在 url 中使用# 作为某个值,你需要使用# 的 url 编码版本,即%23,因为# 表示指向页面某些部分的内部链接。见https://www.yourhtmlsource.com/text/internallinks.html & https://way2tutorial.com/html/html_internal_links.php

如果你的网址是http://localhost/user_notes/user.php?id=%231234,那么你会得到#

echo $_GET['id'];

【讨论】:

    猜你喜欢
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 2014-06-13
    • 1970-01-01
    相关资源
    最近更新 更多