PHP &URL 的哈希/片段部分 [英] PHP & Hash / Fragment Portion of URL

查看:26
本文介绍了PHP &URL 的哈希/片段部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来保存 url 的哈希部分并作为 PHP 变量.这个想法有点古怪,但请耐心等待...

I am trying to find a way to save the hash portion of a url and as a PHP variable. This idea is a bit kooky, but bear with me...

我想从以下 URL 中提取位置"片段并将其保存为 PHP 变量.

I'd like to extract the "location" fragment from the following URL and save it as a PHP variable.

http://www.example.com/#location

但是,此链接上的讨论表明URL 的片段只能通过 JavaScript 访问.

However, discussion at this link indicates that the fragment of a URL is only reachable through JavaScript.

但是是否可以创建一个链接,其中片段在 URL 中重复,由 PHP 解析,然后通过 mod rewrite 删除?所以……

But would it be possible to create a link where the fragment is duplicated in the URL, parsed by PHP, and then removed by mod rewrite? So....

原始网址:

http://www.example.com/location/#location

PHP 通过 URL 中的简单位置"获取位置变量

PHP gets location variable thanks to the plain "location" in the URL

Apache 然后将链接重写为:

Apache then rewrites the link to:

http://www.example.com/#location

我很想知道是否有一种优雅的方法可以解决这个问题.

I'm curious to know if there is an elegant way to solve this problem.

推荐答案

您需要使用 Javascript 才能阅读此内容.有几个不同的选项 - 在页面加载时,您可以使用 XmlHTTPRequest(AJAX 请求)来告诉服务器附加的 URL 参数是什么.或者,您可以检查是否有其他参数(也可以通过 Javascript),如果找到,请回发到其他 URL,该 URL 将这些参数编码到 URL 本身中.

You'll need to use Javascript to read this. There are a few different options - upon page load, you could use an XmlHTTPRequest (AJAX request) to tell the server what the additional URL parameters were. Alternatley you could check to see if there are additional parameters (also via Javascript), and if you find any, post back to a different URL that has these parameters encoded into the URL itself.

这篇关于PHP &URL 的哈希/片段部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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