获取完整的URL,包括哈希后的查询字符串 [英] getting the full url including the query string after hash

查看:198
本文介绍了获取完整的URL,包括哈希后的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取完整的URL,包括hash tag之后的字符串参数?我尝试回声

How to get the full URL including the string parameter after hash tag? I try to echo

$url = $_SERVER['REQUEST_URI'];
echo $url;

hash tag之后的字符串不会读取.

the string after the hash tag wont read.

推荐答案

Pekka的评论应该是答案. 哈希标记后的字符串参数未发送到服务器,仅适用于浏览器.

Pekka's comment should be an answer. The string parameter after the hash tag is not sent to the server, it's for the browsers eyes only.

这意味着服务器端代码(在您的情况下为PHP)没有此信息.客户端代码(浏览器,javascript等)可以.

This means that serverside code (PHP, in your case) does not have this info. The clientside code (the browser, javascript, ...) does.

理想情况下,

  • ?之后的部分?是服务器的信息.把你的一切 服务器需要在这里
  • #号后面的部分是有关客户的信息.把你的一切 客户需求在这里.它称为片段标识符(感谢
  • the part after the ? is info for the server. Put everything your server needs here
  • the part after the # is info for the client. Put everything your client needs here. It's called the Fragment Identifier (Thanks Tim).

从历史上看,#后面的部分最常用于使浏览器快速滚动到页面上定义的锚点.如今,它更常用于保存客户端的状态信息.

Historically, the part after the # was most often used to have your browser quicky scroll to a defined anchor on the page. Nowadays, it is more often used to hold state information for the client.

您可以让javascript将此信息发送到服务器,或根据此信息执行其他操作. AJAX是您的朋友.

You could have javascript send this info to the server, or perform different actions based on this info. AJAX is your friend.

这篇关于获取完整的URL,包括哈希后的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆