A better way...

Joined
Dec 26, 2008
Messages
781
Reaction score
226
Well the website I'm working on uses a hash value in the URL to determine the page that it's on, so it would be something like: yoursite.com/#home

I've been searching and discovered that the hash value of the URL is only sent to the client, not the server; so I would have to get it through javascript using window.location.hash. My problem is transferring that to PHP. The only way that I've thought of is saving it to a cookie and then having the PHP read that cookie. Can anyone think of a better way?
 
Why not just use $_GET to determine the page?

Example:
http://page.com?page=frontpage
$page = $_GET['page'];
That's how I usually do it, but the site already has the paging system using the hash value. Chances are I'm going to redo it since using $_GET is alot easier. I'm just wondering if there's an easy way to get the hash value into PHP :0
 
The pages I've used had JavaScript doing ajax requests based on the hash values so the PHP code didn't have to know anything about hash.

For example http://domain.tld/#home would load index.php which has JavaScript to load home.php using an ajax query.
 
The pages I've used had JavaScript doing ajax requests based on the hash values so the PHP code didn't have to know anything about hash.

For example http://domain.tld/#home would load index.php which has JavaScript to load home.php using an ajax query.
While this can also be done in only Javascript without the requirement of using ajax at all.
What you can do in PHP is let PHP know that it needs todo something with the hash.

example:
PHP copies the hash
yoursite.com/#xxx
than the php will use
xxx.php

what you can also do is make a MySQL database and link different hashes to different files or texts.
 
Last edited:
Back