View Full Version : fragment identifier as variable
marcus1060
06-28-2008, 12:27 AM
Right now I have a page that the links are like page.php?t=item#item
With the variable so that PHP can have an item open (instead of it being closed by default) and the fragment identifier bring the object into view.
Can I somehow just make PHP get the variable from fragment id?
So I can just do page.php#item?
Thanks!
Fou-Lu
06-28-2008, 12:44 AM
I think your outta luck on this one. Best I know, PHP ignores incoming fragments. mod_rewrite may be able to do this for you though. The only php usage I can think of is to make use of a session and the query string, and redirect the user back to the same page with the fragment attached.
Lets see if I can wing up some code for you:
<?php
session_start();
if (isset($_GET['t']) && !isset($_SESSION['redirect']))
{
$_SESSION['redirect'] = true;
header('Location: ' . $_SERVER['SCRIPT_NAME'] . '?t= ' . $_GET['t'] . '#' . $_GET['t']);
}
// Do stuff
unset($_SESSION['redirect']);
?>
So lets see, if the t is sent, and redirect has not happened, set the sessions redirect to true. Then send a header back to this page with the t and fragment. Do your stuff as it will get back to this page and bypass the first if. At the end, unset the redirect session value so we don't do bypass the redirect on each page load.
Something like that may work. I think that mod_rewrite would be easier though...
marcus1060
06-28-2008, 12:56 AM
Yeah, I don't think I really want to go that far. :)
I'd look into mod_rewrite, but unfortunately it's IIS the server the site is one, and I know little about it.
Fou-Lu
06-28-2008, 01:56 AM
With IIS, I have no idea what you would need to do sorry. mod_rewrite is Apache exclusive if I'm not mistaken.
Inigoesdr
06-28-2008, 10:33 PM
There are some commercial implementations of mod_rewrite for IIS, but none that I know of for free.
$fragment = parse_url('http://google.com/#foo', PHP_URL_FRAGMENT);
should do it. You need the full URL including scheme and domain though, it won't (I don't think) work just for a relative path ('/foo/page.php#bar')
Inigoesdr
06-29-2008, 04:05 PM
$fragment = parse_url('http://google.com/#foo', PHP_URL_FRAGMENT);
should do it. You need the full URL including scheme and domain though, it won't (I don't think) work just for a relative path ('/foo/page.php#bar')
That won't get the fragment/anchor on the receiving end because it's not sent to the server.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.