OT: Php hash

Discussion in 'HTML' started by Neredbojias, Jul 13, 2007.

  1. Neredbojias

    Neredbojias Guest

    Suppose I have a normal link like:

    <a href="some/path/ululation.php#fragg">Click Dis</a>

    Now, in the target page, "ululation.php", I know how to get the pathname
    and I even know how to get a possible query name (-not shown here.)

    Does anyone know how to address the hash ("fragment" in php)? I've tried
    $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] and things using referer -
    all to no avail.

    Thanks.

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 13, 2007
    #1
    1. Advertising

  2. Neredbojias wrote:

    > Suppose I have a normal link like:
    >
    > <a href="some/path/ululation.php#fragg">Click Dis</a>
    >
    > Now, in the target page, "ululation.php", I know how to get the
    > pathname and I even know how to get a possible query name (-not shown
    > here.)
    >
    > Does anyone know how to address the hash ("fragment" in php)? I've
    > tried $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] and things
    > using referer - all to no avail.


    You should have: <a name="fragg"></a> or <div id="fragg">
    somewhere in ululation.php, right? S'far as I know, it should jump
    right to that part of the page.

    --
    -bts
    -Motorcycles defy gravity; cars just suck
    Beauregard T. Shagnasty, Jul 13, 2007
    #2
    1. Advertising

  3. Neredbojias wrote:
    > Suppose I have a normal link like:
    >
    > <a href="some/path/ululation.php#fragg">Click Dis</a>
    >
    > Now, in the target page, "ululation.php", I know how to get the pathname
    > and I even know how to get a possible query name (-not shown here.)
    >
    > Does anyone know how to address the hash ("fragment" in php)? I've tried
    > $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] and things using referer -
    > all to no avail.


    The hash or fragment part of the URL is not sent to the server, but is
    processed internally in the browser. You can only "capture" is with
    client side.


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Jul 13, 2007
    #3
  4. Neredbojias

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 03:38:47
    GMT Jonathan N. Little scribed:

    > Neredbojias wrote:
    >> Suppose I have a normal link like:
    >>
    >> <a href="some/path/ululation.php#fragg">Click Dis</a>
    >>
    >> Now, in the target page, "ululation.php", I know how to get the
    >> pathname and I even know how to get a possible query name (-not shown
    >> here.)
    >>
    >> Does anyone know how to address the hash ("fragment" in php)? I've
    >> tried $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] and things
    >> using referer - all to no avail.

    >
    > The hash or fragment part of the URL is not sent to the server, but is
    > processed internally in the browser. You can only "capture" is with
    > client side.


    That is exactly the effect I am experiencing, but....

    The server *has to* receive it somehow, not so?, for how else does it get
    to the visitor's userAgent?

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 13, 2007
    #4
  5. Neredbojias

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 02:52:24 GMT
    Beauregard T. Shagnasty scribed:

    > Neredbojias wrote:
    >
    >> Suppose I have a normal link like:
    >>
    >> <a href="some/path/ululation.php#fragg">Click Dis</a>
    >>
    >> Now, in the target page, "ululation.php", I know how to get the
    >> pathname and I even know how to get a possible query name (-not shown
    >> here.)
    >>
    >> Does anyone know how to address the hash ("fragment" in php)? I've
    >> tried $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] and things
    >> using referer - all to no avail.

    >
    > You should have: <a name="fragg"></a> or <div id="fragg">
    > somewhere in ululation.php, right? S'far as I know, it should jump
    > right to that part of the page.


    I'm trying to use it as a "pointer" in php, not for the normal function.

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 13, 2007
    #5
  6. Neredbojias wrote:

    > The server *has to* receive it somehow, not so?,


    It doesn't.

    > for how else does it get to the visitor's userAgent?


    It doesn't "get to" the visiter's user agent. It starts at the UA
    and never leaves.

    If you really want to communicate the URL fragment to the server,
    you'd have to use AJAX.

    --
    Toby A Inkster BSc (Hons) ARCS
    [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
    [OS: Linux 2.6.12-12mdksmp, up 22 days, 14:37.]

    demiblog 0.2.0 Released
    http://tobyinkster.co.uk/blog/2007/06/28/demiblog-0.2.0/
    Toby A Inkster, Jul 13, 2007
    #6
  7. Neredbojias wrote:

    > Beauregard T. Shagnasty scribed:
    >> Neredbojias wrote:
    >>> Suppose I have a normal link like:
    >>>
    >>> <a href="some/path/ululation.php#fragg">Click Dis</a>

    >>
    >> You should have: <a name="fragg"></a> or <div id="fragg">
    >> somewhere in ululation.php, right? S'far as I know, it should jump
    >> right to that part of the page.

    >
    > I'm trying to use it as a "pointer" in php, not for the normal
    > function.


    You didn't mention that. So then under normal circumstances, you will
    have to do something like:

    <a href="some/path/ululation.php?p=fragg">Click Dis</a>

    $somevar = $_GET['p'];

    and then have your script jump to the id or anchor. But why make it
    difficult? Don't you already have the id/anchor?

    --
    -bts
    -Motorcycles defy gravity; cars just suck
    Beauregard T. Shagnasty, Jul 13, 2007
    #7
  8. Neredbojias

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 10:59:45 GMT
    Toby A Inkster scribed:

    > Neredbojias wrote:
    >
    >> The server *has to* receive it somehow, not so?,

    >
    > It doesn't.
    >
    >> for how else does it get to the visitor's userAgent?

    >
    > It doesn't "get to" the visiter's user agent. It starts at the UA
    > and never leaves.


    Yep, yep, yep. JL (and you) are right. I sees it now and can only say -
    that sucks.

    > If you really want to communicate the URL fragment to the server,
    > you'd have to use AJAX.


    -As I'm doing now. That sucks, too. But thanks for the info.

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 13, 2007
    #8
  9. Neredbojias

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 13:03:53 GMT
    Beauregard T. Shagnasty scribed:

    >> I'm trying to use it as a "pointer" in php, not for the normal
    >> function.

    >
    > You didn't mention that. So then under normal circumstances, you will
    > have to do something like:
    >
    > <a href="some/path/ululation.php?p=fragg">Click Dis</a>
    >
    > $somevar = $_GET['p'];
    >
    > and then have your script jump to the id or anchor. But why make it
    > difficult? Don't you already have the id/anchor?


    Has to be on the url as it acts as a session variable. I'm using a
    javascript speed-determining function the results of which I want
    communicated to the server to determine a hi-speed vs. lo-speed connection
    throughout. The trouble with using a search string is that it reloads the
    page non-transparently.

    What I have now is more-or-less working, but a true php session would be an
    improvement.

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 13, 2007
    #9
  10. Neredbojias wrote:
    > Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 03:38:47
    > GMT Jonathan N. Little scribed:
    >
    >> Neredbojias wrote:


    > That is exactly the effect I am experiencing, but....
    >
    > The server *has to* receive it somehow, not so?, for how else does it get
    > to the visitor's userAgent?
    >

    It doesn't as Toby says. The fragment is stripped off by the UA and is
    stored in the UA's memory. The server only receives the
    scheme, host, port, [user], [password], path, and [query]
    then when the page loads the UA uses the stored fragment to find the
    hash on the page if it exists.

    You can see this in action by tailing the access_log of a web server.
    For example on my site the URL:

    http://www.littleworksstudio.com/gallery.php?sr=10&byid=ckcs#BMckcs0223

    shows as:

    ###.###.###.### - - [13/Jul/2007:11:22:04 -0400] "GET
    /gallery.php?sr=10&byid=ckcs HTTP/1.1" 200 30228 "-" "Mozilla/5.0
    (Windows; U; Windows NT 5.0; en-US; rv:
    1.8.1.4) Gecko/20070509 SeaMonkey/1.1.2 Mnenhy/0.7.5.0"

    Note the missing fragment "#BMckcs0223"

    I came across this a while back when I converted an old JavaScript
    navigation management system to PHP which generated the breadcrumb trail.

    I did read some discussion on including the fragment in server-side
    processing, but who knows if it will ever change.

    A workaround is to pass as query string value and convert to a fragment
    as BTS suggested.


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Jul 13, 2007
    #10
  11. Neredbojias

    Neredbojias Guest

    Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007 15:30:21
    GMT Jonathan N. Little scribed:

    > Neredbojias wrote:
    >> Well bust mah britches and call me cheeky, on Fri, 13 Jul 2007
    >> 03:38:47 GMT Jonathan N. Little scribed:
    >>
    >>> Neredbojias wrote:

    >
    >> That is exactly the effect I am experiencing, but....
    >>
    >> The server *has to* receive it somehow, not so?, for how else does it
    >> get to the visitor's userAgent?
    >>

    > It doesn't as Toby says. The fragment is stripped off by the UA and is
    > stored in the UA's memory. The server only receives the
    > scheme, host, port, [user], [password], path, and [query]
    > then when the page loads the UA uses the stored fragment to find the
    > hash on the page if it exists.


    Yes, I see that's correct. Somehow I had it in my head that the server
    had to send it to the visitor's browser as an _entity_ (I suppose you'd
    say.} Not so, of course.

    > You can see this in action by tailing the access_log of a web server.
    > For example on my site the URL:
    >
    > http://www.littleworksstudio.com/gallery.php?sr=10&byid=ckcs#BMckcs0223
    >
    > shows as:
    >
    > ###.###.###.### - - [13/Jul/2007:11:22:04 -0400] "GET
    > /gallery.php?sr=10&byid=ckcs HTTP/1.1" 200 30228 "-" "Mozilla/5.0
    > (Windows; U; Windows NT 5.0; en-US; rv:
    > 1.8.1.4) Gecko/20070509 SeaMonkey/1.1.2 Mnenhy/0.7.5.0"
    >
    > Note the missing fragment "#BMckcs0223"


    Yep. Very insightful.

    > I came across this a while back when I converted an old JavaScript
    > navigation management system to PHP which generated the breadcrumb
    > trail.
    >
    > I did read some discussion on including the fragment in server-side
    > processing, but who knows if it will ever change.
    >
    > A workaround is to pass as query string value and convert to a
    > fragment as BTS suggested.


    Nope, no query strings. _Adding_ one reloads the page in a way I don't
    like. What I finally resigned myself to was a current-session, non-
    written cookie with my previous old system as backup. The cookie seems
    to work perfectly; the backup most of the time. (What goes wrong there
    is hard to explain, but it's nothing invalid or errorwise. I "lose" the
    hash, that's all.)

    Thanks again for all the help.

    --
    Neredbojias
    A self-made man who worships his creator
    Neredbojias, Jul 14, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    471
    Tim Arnold
    Oct 3, 2006
  2. Ted Zeng
    Replies:
    0
    Views:
    600
    Ted Zeng
    Oct 13, 2006
  3. Rajive Narain
    Replies:
    0
    Views:
    1,482
    Rajive Narain
    Sep 18, 2009
  4. rp
    Replies:
    1
    Views:
    478
    red floyd
    Nov 10, 2011
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    581
    David A. Black
    Jul 2, 2008
Loading...

Share This Page