简体   繁体   English

如何在PHP中使用哈希传递参数

[英]How to pass parameters with hash in PHP

Recently when i saw google results page, the query and other parameters where passed with # (hash) instead of the usual "?" 最近,当我看到google结果页面时,查询和其他参数以#(哈希)而不是通常的“?”传递

Also, in facebook i saw the same thing. 另外,在facebook上我看到了同样的事情。 This was quite interesting and after a simple search with google , i found the results related to perl and Ruby but no result with PHP. 这很有趣,在用google进行简单搜索后,我发现与perl和Ruby有关的结果,但与PHP无关。

Is it possible to pass parameters with # in PHP instead of "?" 是否可以在PHP中用#而不是“?”传递参数? or is this possible only with perl/Ruby. 或者这仅在perl / Ruby中可行。 This will be useful and search engines will not parse the parameters in the URLs. 这将很有用,搜索引擎将不会解析URL中的参数。

Any ideas will be helpful to me. 任何想法对我都会有帮助。

Traditionally, the # told the browser to automatically scroll to a particular point in the page, which was (and still is) often used to implement links from one part of a page (eg a table of contents) to another (eg a section heading). 传统上, #告诉浏览器自动滚动到页面中的特定点,该点过去(现在仍然)用于实现从页面的一部分(例如目录)到另一部分(例如节标题)的链接。 )。

However, it also has the effect of causing the URL containing the # to be recorded in the history, even if it's identical to the previous URL except for the # and what follows it. 但是,它也具有使包含#的URL记录在历史记录中的作用,即使它与先前的URL相同(除了#及其后面的内容)也是如此。 (In other words, the user is still on the same page.) This means that the back button can be used to get back to the state that you were previously in, even if that state-change doesn't correspond to a page-load. (换句话说,用户仍在同一页面上。)这意味着后退按钮可用于返回到您之前的状态,即使该状态更改与某个页面不对应-加载。

Modern AJAX applications therefore often use it to signify that something has happened that the user might want to "go back" from. 因此,现代AJAX应用程序经常使用它来表示发生了某些事情,用户可能想“回头”。

Nope, it is not possible. 不,这是不可能的。
What have you seen is just a decoration, to reflect an AJAX call in the address bar. 您所看到的只是一种装饰,可以在地址栏中反映AJAX调用。

No matter what language you choose - all of them sits on the server side and communicate with browser using HTTP protocol. 无论选择哪种语言,它们都位于服务器端,并使用HTTP协议与浏览器进行通信。 And no anchor allowed in HTTP requests. 并且HTTP请求中不允许使用锚。 That's completely client side thing 那完全是客户端的事情

You are running into confusion in your search results because the term hash is overloaded , as is the concept of parameter passing. 您会在搜索结果中遇到混乱,因为术语“哈希”已超载 ,参数传递的概念也是如此。

You are seeing references to the concept of passing values in a hash beacause an associative array is called a hash in some languages (which is short for a hash table). 您正在看到有关在哈希中传递值的概念的引用,因为在某些语言中, 关联数组称为哈希(哈希表是哈希表的缩写)。

The # character is also confusingly named. #字符也容易混淆。 It is called, "hash", "pound", "number" and "octothorpe". 它被称为“哈希”,“英镑”,“数字”和“八字形”。 Since I grew up in the US, I call it a "pound sign" in my head, which is likely annoying to users of more British English, and is no less fraught with potential for confusion (consider "£"). 自从我在美国长大以来,我就称其为“英镑符号”,这可能会给使用更多英式英语的用户带来烦恼,并且同样充满混乱的可能性(考虑“£”)。

Passing function arguments in a hash in Perl is a nice way to get named arguments for a routine. 在Perl中的哈希中传递函数参数是获取例程命名参数的一种好方法。 PHP has positional arguments only, but using an Array works nicely there. PHP仅具有位置参数,但在此处使用Array效果很好。

Many web libraries use a hash/associative array type structure for form values. 许多Web库将哈希/关联数组类型结构用于表单值。 Keys are typically the field id, and values are the field values. 键通常是字段ID,值是字段值。

In a URI the # denotes the start of the fragment specifier. 在URI中, #表示片段说明符的开始。 It identifies a part of the page that the URI points to. 它标识URI指向的页面部分。 It is generally not used to pass request information from the client back to the server. 通常,它不用于将请求信息从客户端传递回服务器。

there probably is some server rewriting or so. 大概有一些服务器重写。 Example with apache server, you can handle some uri like apache服务器示例,您可以处理一些uri

http://www.mysite.com#something

and rewrite it as 并重写为

http://www.mysite.com/perl/script.pl?data=something

and so process it as a simple GET query to your script.pl 然后将其作为对您的script.pl的简单GET查询进行处理

This is all server-side processing, un-visible to the client 这是所有服务器端处理,对客户端不可见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM