$_GET difference when calling URL with or without anchor [duplicate] - php

This question already has answers here:
Why is the hash part of the URL not available on the server side?
(4 answers)
Closed 4 years ago.
Why does $_GET deliver different results if I call an URL with an anchor compared to without?
example:
https://www.myurl.com/#anchor?param1=x&param2=y
if I read the GET params, REQUEST, $_SERVER['QUERY_STRING'], parse_url($url, PHP_URL_QUERY)
all are emtpy
but with
https://www.myurl.com/?param1=x&param2=y
everything works as expected.
Can anyone explain me this please?

Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).
Check the explanation from here.

Anchors go at the end, hence the name. :)
https://www.myurl.com/?param1=x&param2=y#anchor

Related

What does ? stand for in PHP (after href operator)? [duplicate]

This question already has answers here:
What is the "?" symbol in URL used for in php?
(7 answers)
What the meaning of "?" in the PHP URL [duplicate]
(7 answers)
Closed 4 years ago.
I have the following problem:
I use a template page for a specific application, and for the login through "steam" there is a button. The button refers to a php file, and in the php file you can find the following line of code:
<a href="?login"><div id="sign-in-steam" style="margin-left: 74px;color: black;">
What does the "?login" exactly mean, I know it stands for a file but I cant find a file named like that, can anyone help me out?
The part behind the question mark in any URL is the Query String as per RFC 3986 section 3.4 and hence is not a PHP functionality (even though PHP can read it, see PHP $_SERVER superglobal docs, especially $_SERVER['QUERY_STRING']).
The hyper reference
?login
refers to the web-apps main page, which gets called using the parameter login a a GET parameter.
Quite likely, this would call the same script equivalently:
index.php?login

how to get the entire url in php including the # symbol with values [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
abcd.com/indexreadmore.php?#cat2
This is what the url in which I want to get all the parts like above mentioned, I can get a bit but not able to get the #cat2 and help me fetch entire url in php from the url bar.
The hashtags are not sent to the server, only the browser so PHP wouldn't be able to parse that from the address. You'd have to use javascript:
<script type="text/javascript">alert(window.location.hash);</script>
You cannot get the URL after the # in PHP..
The maximum you can attain is abcd.com/indexreadmore.php , To verify this you could just do a print_r($_SERVER); on your PHP code.
The content after the # can be retrieved only through JavaScript.
If you mean to parse the url, then there is parse_url function.
var_dump(parse_url('abcd.com/indexreadmore.php?#cat2'));
The browser does not send the hash fragment to the server if you mean get it in indexreadmore.php.

/?q=#/ in URL Query String? [duplicate]

This question already has an answer here:
What is the shebang/hashbang for?
(1 answer)
Closed 9 years ago.
/?q=#/ in Query String, sometimes I saw in URL of facebook and twitter, what it is and why is it used?
Please explain in detail. I query it most of time in google but have not found satisfactory results.
I think it used in Ajax based framework.
It is for updating the page's URL without fully reloading the page. /?q= is just an empty variable in the query string. But, everything after a # is actually in the hash part of the URL. That was originally used to automatically scroll a page to an anchor (<a name="blah">). It is accessible via JavaScript, and because it doesn't reload the page, it is perfect for URLs that work when copy-pasted to the URL box, change when you do stuff on the page, but still keep everything loaded.
Shortly: /?q= is an empty variable in the query string, #/ and everything after that is data for JavaScript to process. The slash(es) in the hash string make it look like it is also a part of the directory structure.
Section 3 of RFC 3986 may be helpful.
The /?q= is a query string, where the parameter named q is blank/empty.
Everything after the # is called the fragment. Sometimes it's used to jump to a bookmark on the page, but, usually it's just some data that the Javascript running in your browser can use. If you change the part after # in the URL, your page doesn't reload, but, the Javascript in your browser can react to it.

using anchors #value in URL, can I call and use this value in php? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can PHP read the hash portion of the URL?
Hi,
I want to go to a part of my web page where a div called bla bla bla is located.
Using this: http://www.mysite.com/mypage#28 I get there.
But I also need that number to process in php. Does the # work like a ? ($_get) as well?
How do I do that otherwise?
Thanks
I agree with middaparka, Hash values is a client side values can not be loaded from server side, as Facebook Dynamic Url Loading technique
so you can read it is value from a function, and call that function onload of page to do what you need.
In theory you can use the parse_url function to obtain this, via the PHP_URL_FRAGMENT option. However, in practice I'm pretty sure that there's no guarantee that the browser will pass this information to the server. (i.e.: It won't show up in $_SERVER['REQUEST_URI'], so there's no way to pass this information into parse_url in the first place.)
As such, you'd need to obtain this client-side via JavaScript and forward it to the server. To do this you can use window.location.hash.
e.g.: <script>alert('The hash value is: '+window.location.hash);</script>
There is JQuery Plugin "hashchange" using that you can send Ajax request when the hash is changed everytime. You can even bookmark it.
http://benalman.com/projects/jquery-hashchange-plugin/
Check out the demo at http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/

What does /#!/ mean in URL? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What's the shebang (#!) in Facebook and new Twitter URLs for?
It usually comes straight after the domain name.
I see it all the time, like in Twitter and Facebook urls.
Is it some special sort of routing?
# is the fragment separator. Everything before it is handled by the server, and everything after it is handled by the client, usually in JavaScript (although it will advance the page to an anchor with the same name as the fragment).
after # is the hash of the location; the ! the follows is used by search engines to help index ajax content. After that can be anything, but is usually rendered to look as a path (hence the /). If you want to know more, read this.

Categories