Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get local anchor name from request

2 views
Skip to first unread message

Roger Rene Kommer

unread,
May 14, 2003, 6:11:51 PM5/14/03
to
Hi,

I call a php page via:

http://myserver/myphp.php?id=bla#LocalAnchor

Is there any way inside the PHP script to retrive
the 'LocalAnchor' name, or at least the complete
URL.

REQUEST_URI, QUERY_STRING seems to strip
away the LocalAnchor

Regards,
Roger


John Dunlop

unread,
May 14, 2003, 7:17:22 PM5/14/03
to
Roger Rene Kommer wrote:

> http://myserver/myphp.php?id=bla#LocalAnchor
>
> Is there any way inside the PHP script to retrive
> the 'LocalAnchor' name,

Take a look at the parse_url function:
http://www.php.net/manual/en/function.parse-url.php

Cheers,

--
Jock

Roger Rene Kommer

unread,
May 14, 2003, 9:18:59 PM5/14/03
to
Hi,
"John Dunlop" <jdu...@cis.strath.ac.uk> schrieb im Newsbeitrag
news:MPG.192cdcf3c...@news.freeserve.net...

The problem is not to parse an URL, but to find out with what LocalAnchor
(called 'fragment' in php docs)
the current .php was called.

With the global variables provided from PHP inside the php page I can only
find out the url-parts:
http://myserver/myphp.php?id=bla
but not
http://myserver/myphp.php?id=bla#LocalAnchor

Roger


John Dunlop

unread,
May 15, 2003, 5:07:39 AM5/15/03
to
Roger Rene Kommer wrote:

> The problem is not to parse an URL, but to find out with what LocalAnchor
> (called 'fragment' in php docs) the current .php was called.

Ah. You can't do that. What are you trying to do?

Cheers,

--
Jock

Roger Rene Kommer

unread,
May 15, 2003, 6:27:51 AM5/15/03
to

"John Dunlop" <jdu...@cis.strath.ac.uk> schrieb im Newsbeitrag
news:MPG.192d6935c...@news.freeserve.net...
For a CMS I want to redirect URL-requests dynamically to another web.
This works quite well for normal URLs, but I want also jump to the local
anchor target in the new page.

Roger


John Dunlop

unread,
May 15, 2003, 7:05:09 AM5/15/03
to
Roger Rene Kommer wrote:

> For a CMS I want to redirect URL-requests dynamically to another web.
> This works quite well for normal URLs, but I want also jump to the local
> anchor target in the new page.

I assume you're using the header function, like so:

header("Location: http://www.example.com/");

You can simply append a fragment identifier to the absolute URL
you're redirecting to. The server should then send the whole URL
reference to the client, which should, in turn, interpret the whole
URL reference. For example,

header("Location: http://www.example.com/foo#bar");

Is this what you're doing so far?

The reason why you can't access the fragment identifier of a request
directly through PHP is that such information isn't sent to the
server; so PHP, being a server-side language, has no way of seeing
it.

Technically, the fragment identifier isn't even part of the URL at
all. It is part of an URL reference, composed of an URL and an
optional fragment identifier. This common misunderstanding is further
promoted by PHP's parse_url function. :-(

The authoritative source for such information is the relevant RFC
[1]. Specifically, you should read section 4.1, which reads:

When a URI reference is used to perform a retrieval action on
the identified resource, the optional fragment identifier,
separated from the URI by a crosshatch ("#") character, consists
of additional reference information to be interpreted by the user
agent after the retrieval action has been successfully completed.
As such, it is not part of a URI, but is often used in
conjunction with a URI.

Thus, we can conclude that browsers do not send the fragment
identifier to the server. Instead they keep it, and apply it after
the resource has been sent to them. Of course, to be of any use
whatsoever, the identified fragment must be defined within that
resource.

I hope this has cleared something up. :-)

Cheers,

[1] RFC 2396, "Uniform Resource Identifiers (URI): Generic Syntax",
http://www.ietf.org/rfc/rfc2396.txt

--
Jock

Roger Rene Kommer

unread,
May 15, 2003, 8:08:02 AM5/15/03
to
Hi,

Thank you for your good explanation.
I didn't know, that fragments are not sent
to the HTTP server.

The background of what I want to do:
My CMS generates static HTML files, which can be included
into a software package, web page, PDF or HTMLHelp files.
The links inside the CMS sources are referenced via
IDs (simple string identifier), not URLs. The same CMS source can
be used in the software distribution package and the Web-Page.
Because the complete documentation is about ~300 MB I cannot
include it with each software package. So I want redirect each page id
to the main web server, that cannot find in current selected documentation
set.
I can solve the problem, that the fragment part is not send to the HTTP
server.
I simply have to not to generate a link:
http://www.example.com/frwid.php?pageid=a_page_id#LocalAnchor
but
http://www.example.com/frwid.php?pageid=a_page_id&fragment=LocalAnchor

I simply wanted to avoid this solution, because I have to reorganize some
parts
of my CMS code, which was not necessary with the first solution.

Roger

0 new messages