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

查看:79
本文介绍了PHP& 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重写删除?所以....

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....

原始网址:

Original url:

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

PHP由于简单的location 在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参数。 Alternatley,你可以检查是否有其他参数(也通过Javascript),如果你找到任何,请发回到一个不同的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天全站免登陆