简体   繁体   中英

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 "?"

Also, in facebook i saw the same thing. 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.

Is it possible to pass parameters with # in PHP instead of "?" or is this possible only with perl/Ruby. This will be useful and search engines will not parse the parameters in the URLs.

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

Nope, it is not possible.
What have you seen is just a decoration, to reflect an AJAX call in the address bar.

No matter what language you choose - all of them sits on the server side and communicate with browser using HTTP protocol. And no anchor allowed in HTTP requests. 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. PHP has positional arguments only, but using an Array works nicely there.

Many web libraries use a hash/associative array type structure for form values. Keys are typically the field id, and values are the field values.

In a URI the # denotes the start of the fragment specifier. It identifies a part of the page that the URI points to. 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

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

This is all server-side processing, un-visible to the client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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