I am new to PHP Development.
Today I came across the interesting topic of URL fragments, specifically the #
part of URLs.
I searched and found that it's like
www.example.com/foo.html#bar
But I don't understand why this #bar
is needed. Or how to read it in PHP?
A hash sign (#) in a URL is referred to as a fragment. Historically, URL fragments have been used to automatically set the browser's scroll position to a predefined location in the web page. In that sense, if a URL refers to a document, then the fragment refers to a specific subsection of that document.
The primary resource is identified by a Uniform Resource Identifier (URI), and the fragment identifier points to the subordinate resource. The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.
Fragment identifiers are not sent to the server. The hash fragment is used by the browser to link to elements within the same page.
URL parameters are used to pass information to the page. URL fragments are used from pointing and scrolling to elements on the HTML document. A URL can have multiple parameters. A URL cannot have more than one fragment.
A fragment is an internal page reference, sometimes called a named anchor. It usually appears at the end of a URL and begins with a hash (#) character followed by an identifier. It refers to a section within a web page.
In HTML documents, the browser looks for an anchor tag with a name attribute matching the fragment.
There are a few things about the fragments, the most important may be that they aren't sent in HTTP request messages but you can find some more info about them on this page.
Javascript can manipulate fragments on the current page which can be used to to add history entries for a page without forcing a complete reload.
It's unable to read it by php. It uses by client side (browser) for hash navigation, but you can write JS code to handle hash change and send async request to your server side (php) and display result on your page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With