Can you access a # in PHP?

Associate
Joined
8 Aug 2008
Posts
302
Hi

Looking to do a facebook style gallery. With theirs they seem to have a pid=value and then when you navigate you get a second #pid=value.

Now I can access this post hash value in Javascript which is probably what'll I'll use to catch and reload the php gallery to show the correct image on direct link, just wondering if anyone knew if PHP could get it directly? $_SERVER["REQUEST_URI"]; only gives me the querystring not the hash after?

Thanks
 
As far as I know, anything following the # isn't technically part of the URI and isn't even sent in the request headers, so no, I don't think you can.
 
The contents after # is used as a page anchor, so I presume Facebook are doing something funny in Javascript to work out where to scroll the browser to :) (unless the anchor really is just 'pid=xyz')
 
Hi Beansprout

Yeah I thought maybe it was that, though earlier I was in a gallery where the page was actually reloading!

I can get the value after the hash with

Code:
var h = String(document.location).split ('#')[1];

in some javascript which I think I'll call first time the page is loaded so if someone is linking directly I can get it to do a call back to the required php file with the id in the querystring.
 
I think there's an easier way to get it - try var h = window.location.hash;

You're doing it the right way though, at the page load event fire some javascript to choose the first image depending on that hash value.
 
Hi Huppy

I was wondering about firing the function on the page load. Thing is I want to use a require for the file that handles the whole ajax loading, only issue is it'll just be an id'd div so won't have it's own body to process onload.

Is there a better way of firing the javascript other than say loading a 1x1 pixel to do it?

Basically I'm going to get it to differentiate a first load from a reload by adding a random number to the querystring when the request comes from a back and forth navigation which won't exist when the page is clicked nav'd to from a previous page or the address is pasted in.

I could iframe which is what I've done for other mini gallery navs, but then you get size issues of the space used up.
 
I'm not quite with you on your 1x1 pixel or the iframe, or the need for any ajax.

Altering the value of the # doesn't reload the page - provided the href doesn't point at a different page it only attempts to jump to a certain point in the same page without reloading it.

If you're only working with an image file, all you would do is alter the src of the main <img /> depending on the value after the #, at the page load. 'Next' and 'Previous' buttons would have some simple javascript behind them to alter the <img />'s src and the links on 'Next' and 'Previous'. Unless, that is, you wanted to attempt to cache what the next image might be before the visitor hits the 'next' link.
 
Ahh well I'm fetching comments and tags and all sorts so it's more of a complete shift of content without a refresh I'm looking for.

Beansprout - Yeah maybe sessions would do ok, it's just with a calender to form input I did recently I'd used a really good example from someone who'd got the page to output the divs only once by checking to see if a random figure was in the querystring making it a call from the Javascript.
 
Back
Top Bottom