oskom Posted August 8, 2008 Share Posted August 8, 2008 Hey all, Is there some $_SERVER method, or anything else, that will allow PHP to get the hash from a url? In other words, I want to take a url like "www.mydomain.com/#1234" and have PHP get the hash and use it as a variable for other purposes. Does this sound do-able? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/ Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 www.yourdomain.com/?hash=yourhasgoesherewoooooo <?php $Hash=$_GET['hash']; if ($Var==md5($Hash) { // it matches } ?> Simple enough? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611867 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Jabop, technically, the hash is the #foo after the URL, not a GET parameter. Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611872 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 That's exactly what I'm trying to avoid. I don't want to pass it as a variable. This is for an all AJAX site where the unique url's(in theory) will be created in the hash. I can create a particular page from javascript with the hash, but I need to do it with PHP instead...Google searchable!!!! The only way I can make a unique url for each page(i.e. effect the address without actually flipping the page) is to hash it with javascript. I need to then be able to cut-n-paste that url with the hash into another browser window and have PHP build the page based on the hash being turned into a variable PHP can use. I hope that wasn't too confusing. Can I achieve that with PHP? Here's an idea: can I cookie the hash and pass that? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611875 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 Well it sounds like you're doing something more complex than I was thinking. I'm not too sure how you'd do that, to be honest. But stepping back a bit and thinking about it, I think a cookie may be the best way without passing it visibly? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611876 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Try: $hash = substr(strrchr('#', $_SERVER['REQUEST_URI']), 1); Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611878 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 @Jabop: The point is to pass it visually so that they can jump to a certain part of an Ajax app. Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611879 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 $hash = substr(strrchr('#', $_SERVER['REQUEST_URI']), 1); DarkWater, In testing, it doesn't appear that $_SERVER['REQUEST_URI'] passes the hash. Otherwise, yes, that would be my method. Unfortunately, PHP isn't getting a hash to sub-string. hmmmmmm... Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611884 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Gimme a minute. There's gotta be some way to get that hash. >_> *Goes to the manual* Edit: Nope, there's no way to directly get the hash, as it's only used client-side. You're going to have to set it in a cookie or something. Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611888 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 That was my thinking, which is fine. I would be nice to avoid that step, but if it works, hoooooray!!! Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611890 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 I think window.location.hash might have the hash of the current page (in Javascript), so try working with that to set a cookie for it. Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611891 Share on other sites More sharing options...
alecks Posted August 8, 2008 Share Posted August 8, 2008 as long as you are using ajax, grab the hash w/ ecma and load the rest of the page from a php script Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611894 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 aleks, gotta claim ignorance on this: what is ecma? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611896 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Javascript. Okay, ECMAScript. It's like the new version that has standards or something. Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611899 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 I just checked it out online. Yes, it looks like javascript. Not sure what the difference is yet, though. However, in thinking about it some more, I don't know that the cookie is the solution either. You would have to establish the browser-side cookie with javascript first, then redirect the page(cookie in place) to a PHP page. With Google-searchability at stake, is the googlebot going to be able to take that step? Or does that small amount of javascript intervention break the deal? Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611905 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 All modern browsers have to have their Javascript comply with ECMAScript standards, so they're essentially the same. Don't worry about that. And when you set the cookie, try doing it before the Ajax request and let the PHP handle it. >_> Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611907 Share on other sites More sharing options...
oskom Posted August 8, 2008 Author Share Posted August 8, 2008 Actually, I was hoping to pass the cookie directly to php and have it build the initial page. After that point the ajax would do the rest. Thanks for the info! Link to comment https://forums.phpfreaks.com/topic/118832-need-php-to-get-hash-from-url/#findComment-611987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.