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

Using anchor links within pages defined by GETS

0 views
Skip to first unread message

Mechphisto

unread,
Feb 23, 2009, 12:22:03 PM2/23/09
to
I've a site that uses GETs to pull subpage content.
Like:

http://www.mydomain.com/page.php?pid=sitemap

Now, what if I want to use anchor links? What can I do to make this
work (if possible)?
The traditional: http://www.mydomain.com/page.php#bookmark of course
fails. And I can't add it to the end:
http://www.mydomain.com/page.php?pid=sitemap#bookmark

Any ideas?
Thanks,
Liam

"Álvaro G. Vicario"

unread,
Feb 23, 2009, 12:52:59 PM2/23/09
to
Mechphisto escribió:

I'm not completely sure of what you want to do...

If you want to replace GET parameters with anchor links, well, you
cannot: the browser does not even send them to the server, so they're
unreachable by PHP. Such links are typically used by client-side
applications like Flash movies or JavaScripts code.

If you want to use *both* simultaneously (for different usage), what
prevents you from doing it? Is it a condition imposed by your customer?


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--

Mechphisto

unread,
Feb 23, 2009, 1:37:56 PM2/23/09
to
On Feb 23, 11:52 am, "Álvaro G. Vicario"

<alvaro.NOSPAMTH...@demogracia.com> wrote:
> Mechphisto escribió:
>
> > I've a site that uses GETs to pull subpage content.
> > Like:
>
> >http://www.mydomain.com/page.php?pid=sitemap
>
> > Now, what if I want to use anchor links? What can I do to make this
> > work (if possible)?
> > The traditional:http://www.mydomain.com/page.php#bookmarkof course

> > fails. And I can't add it to the end:
> >http://www.mydomain.com/page.php?pid=sitemap#bookmark
>
> I'm not completely sure of what you want to do...
>
> If you want to replace GET parameters with anchor links, well, you
> cannot: the browser does not even send them to the server, so they're
> unreachable by PHP. Such links are typically used by client-side
> applications like Flash movies or JavaScripts code.
>
> If you want to use *both* simultaneously (for different usage), what
> prevents you from doing it? Is it a condition imposed by your customer?
>

My problem in this convolution is HOW to use both.
The GET (in this example, the value of 'pid'), determines the page
content. 'sitemap' actually triggers PHP script in page.php to grab
and include the content of sitemap.php. So the content in the browser
is derived from sitemap(.php).

Now, an anchor link within sitemap.php, so that one can click a link
and have the browser zip down to that anchor...how do I get that to
work in conjunction with a GET which determines the page content.
Like I said, if I try something like:
http://www.mydomain.com/page.php?pid=sitemap#bookmark
The PHP assumes "sitemap#bookmark" is the value of pid, and there's no
file sitemap#bookmark.php, so it fails.

Ultimately the problem may be just pishpoor design in the first place,
using GETs to grab content to get inserted into one page.php to serve
as a universal page template. There may be to way around this problem
without a redesign. :(
Thanks,
Liam

Michael Fesser

unread,
Feb 23, 2009, 2:06:58 PM2/23/09
to
.oO(Mechphisto)

>My problem in this convolution is HOW to use both.
>The GET (in this example, the value of 'pid'), determines the page
>content. 'sitemap' actually triggers PHP script in page.php to grab
>and include the content of sitemap.php. So the content in the browser
>is derived from sitemap(.php).
>
>Now, an anchor link within sitemap.php, so that one can click a link
>and have the browser zip down to that anchor...how do I get that to
>work in conjunction with a GET which determines the page content.
>Like I said, if I try something like:
>http://www.mydomain.com/page.php?pid=sitemap#bookmark

This is how it's supposed to be.

>The PHP assumes "sitemap#bookmark" is the value of pid, and there's no
>file sitemap#bookmark.php, so it fails.

Then you have an error in your code. Did you encode the '#' maybe?

Micha

Mechphisto

unread,
Feb 23, 2009, 2:23:42 PM2/23/09
to

See, here's the deal, this is what page.php does:

$pid = $_GET['pid']; // get page ID from URL
$filename = 'data/'.$pid.'.php'; // create the filename data will
pull from
$txt_main = file_get_contents($filename);

(Actually, there's some extra code in between which checks to make
sure the submitted value for pid is valid and not a NULL or SQL
injection or something.)

When page.php gets the value of pid, it gets the contents of the
related page, then prints out the content in the appropriate place in
page.php.
So page.php remains the actual page, but the content is always new
based on pid. So, how can you put the href in the link so the URL has
the # and the browser/server understand that once the data is all
loaded...go down to that anchor?

I also tried:
http://www.mydomain.com/page.php#bookmark?pid=sitemap
as that seemed logical based on how the page works...but still no
good.

Thanks for replying.
Liam

Michael Fesser

unread,
Feb 23, 2009, 2:47:57 PM2/23/09
to
.oO(Mechphisto)

No problem so far, but where's the request coming from or how does the
link in the HTML actually look like? What URL is sent to the server?
There's an error somewhere, because your script should never see the
#bookmark part - it's completely handled by the browser and never sent
to the server.

>When page.php gets the value of pid, it gets the contents of the
>related page, then prints out the content in the appropriate place in
>page.php.
>So page.php remains the actual page, but the content is always new
>based on pid. So, how can you put the href in the link so the URL has
>the # and the browser/server understand that once the data is all
>loaded...go down to that anchor?

As already said:

http://www.example.com/page.php?pid=sitemap#bookmark

is the correct way. Anything before the # is the URL and sent to the
server as a request, the part after it is called fragment identifier and
used only in the browser - the server won't see it. But obviously this
doesn't seem to work as it should in your case, so my guess was that
maybe your # is encoded in some way by mistake, e.g.

http://www.example.com/page.php?pid=sitemap%23bookmark

This would yield the result that you see with "sitemap#bookmark" being
passed as the pid parameter.

>I also tried:
>http://www.mydomain.com/page.php#bookmark?pid=sitemap
>as that seemed logical based on how the page works...but still no
>good.

This is wrong, because now 'bookmark?pid=sitemap' would be seen as the
fragement identifier and your script won't receive any parameter at all.

Micha

Mechphisto

unread,
Feb 23, 2009, 3:43:39 PM2/23/09
to
[..snip..]
OMG! I'm an idiot. You totally clue-by-foured me.
The link to the anchor was:
<a href="?pid=sitemap#sep">
I changed it to:
<a href="page.php?pid=sitemap#sep">
and it worked. That's all it was.

Thanks for the replies and helping this clueless one. :)
Liam

Michael Fesser

unread,
Feb 23, 2009, 4:21:05 PM2/23/09
to
.oO(Mechphisto)

>[..snip..]
>OMG! I'm an idiot. You totally clue-by-foured me.
>The link to the anchor was:
><a href="?pid=sitemap#sep">
>I changed it to:
><a href="page.php?pid=sitemap#sep">
>and it worked. That's all it was.

Hmm ... I don't think that this was the reason, because if this link is
used somewhere on page.php, then both URLs point to exactly the same
document and should work well without any difference.

It must have been something else. But anyway, if it works now, OK.

>Thanks for the replies and helping this clueless one. :)

You're welcome.

Micha

Mechphisto

unread,
Feb 23, 2009, 4:27:39 PM2/23/09
to
On Feb 23, 3:21 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Mechphisto)
>
> >[..snip..]
> >OMG! I'm an idiot. You totally clue-by-foured me.
> >The link to the anchor was:
> ><a href="?pid=sitemap#sep">
> >I changed it to:
> ><a href="page.php?pid=sitemap#sep">
> >and it worked. That's all it was.
>
> Hmm ... I don't think that this was the reason, because if this link is
> used somewhere on page.php, then both URLs point to exactly the same
> document and should work well without any difference.

Might is have been because I have in the HTML's HEAD:
<base href="http://www.mydomain.org" />
?

> [..snip..]

Michael Fesser

unread,
Feb 23, 2009, 4:38:27 PM2/23/09
to
.oO(Mechphisto)

Indeed, this would make a difference how the relative URLs are resolved:

?pid=... => http://www.mydomain.org/?pid=...
page.php?pid=... => http://www.mydomain.org/page.php?pid=...

Micha

Curtis Dyer

unread,
Feb 23, 2009, 9:42:19 PM2/23/09
to
Mechphisto <mechp...@gmail.com> wrote:
> On Feb 23, 3:21 pm, Michael Fesser <neti...@gmx.de> wrote:
> > .oO(Mechphisto)
> >
> > >[..snip..]
> > >OMG! I'm an idiot. You totally clue-by-foured me.
> > >The link to the anchor was:
> > ><a href="?pid=sitemap#sep">

This would be a problem if the current page were not already
"page.php".

> > >I changed it to:
> > ><a href="page.php?pid=sitemap#sep">
> > >and it worked. That's all it was.

Do you have an index.php? If the current page were index.php (or
another script/document in the same directory), that's one possible
reason why "page.php?pid=sitemap#sep" worked, but not the former.

> > Hmm ... I don't think that this was the reason, because if this link is
> > used somewhere on page.php, then both URLs point to exactly the same
> > document and should work well without any difference.
>
> Might is have been because I have in the HTML's HEAD:
> <base href="http://www.mydomain.org" />
> ?

Possibly.

> > [..snip..]

In any case, at least you got it working.

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);

0 new messages