Gabriel Spiteri
Gabriel Spiteri

Reputation: 4978

access # part of the URL via PHP

Say I have this url.

http://mydomain.local/category/12/garden#31/decking-treatment

Can the part after the # i.e 31/decking-treatment be retrieved on serverside?

I checked in the $_SERVER and $_REQUEST superglobals but it is not there.

Thanks

Regards Gabriel

Upvotes: 0

Views: 118

Answers (3)

Ignas
Ignas

Reputation: 1965

This is how I sort it:

function reloadPage()
    {
        var hash = location.hash;
        if (hash){
            hash = hash.replace('#', '');
            location.href = hash;
        }
    }

reloadPage();

include this in your js file.

Upvotes: 0

Matt Seymour
Matt Seymour

Reputation: 9415

No, everything after the # is only ever used client side and will not hit the server. If you were to encode the # character before pushing it to the server then you might be able to do something but it would be a little long winded. What is it you are trying to acheive overall?

Upvotes: 1

Quentin
Quentin

Reputation: 944568

Can the part after the # i.e 31/decking-treatment be retrieved on serverside?

No. It is handled client side and never sent to the server. That is why using it for JS based history instead of pushState is a bad idea.

Upvotes: 5

Related Questions