Click here to get back home

URL Parameters to meet W3C validation causes incorrect _GET parameter results

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
URL Parameters to meet W3C validation causes incorrect _GET parameter results The KwikOne 07-17-2008
Posted by The KwikOne on July 17, 2008, 4:56 pm
Please log in for more thread options
Since to have a page validate (HTML and XHTML) you should have your
URL parameters separated by the appropriate separator. However, if an
ampersand is used it needs to be expressed as & (example: ./
index.php?a=1&B=2). But, if that is done, then the _GET or
_REQUEST array element names are incorrect. In the example the _GET
array will be:
_GET['amp;a'] = 1 (instead of _GET['a'] = 1) and _GET['amp;B'] = 2
(instead of _GET['B'] = 2).

So, how do I get around this? Is there any other way other than
looping and stripping the 'amp;' part prior to actually looking for
parameters? What do others do in this situation?

Posted by Olaf Schinkel on July 17, 2008, 5:19 pm
Please log in for more thread options
The KwikOne schrieb:
> Since to have a page validate (HTML and XHTML) you should have your
> URL parameters separated by the appropriate separator. However, if an
> ampersand is used it needs to be expressed as & (example: ./
> index.php?a=1&B=2). But, if that is done, then the _GET or
> _REQUEST array element names are incorrect. In the example the _GET
> array will be:
> _GET['amp;a'] = 1 (instead of _GET['a'] = 1) and _GET['amp;B'] = 2
> (instead of _GET['B'] = 2).
>
> So, how do I get around this? Is there any other way other than
> looping and stripping the 'amp;' part prior to actually looking for
> parameters? What do others do in this situation?
You shold read:
http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2
and:
urlencode();


Posted by Michael Fesser on July 18, 2008, 1:54 am
Please log in for more thread options
.oO(The KwikOne)

>Since to have a page validate (HTML and XHTML) you should have your
>URL parameters separated by the appropriate separator. However, if an
>ampersand is used it needs to be expressed as & (example: ./
>index.php?a=1&B=2).

You only do this if the URL is printed to an HTML page, for example in
an 'a' element:

<a href="./?a=1&amp;B=2">foo</a>

BTW: Don't write "index.html" or "index.php" in URLs, it's not necessary
and bad style.

>But, if that is done, then the _GET or
>_REQUEST array element names are incorrect.

No. The &amp; is interpreted by the browser, the server will never see
it if you click that link.

>In the example the _GET
>array will be:
>_GET['amp;a'] = 1 (instead of _GET['a'] = 1) and _GET['amp;B'] = 2
>(instead of _GET['B'] = 2).
>
>So, how do I get around this?

There's a bug somewhere in your code. Can you post a short code example
or page snippet which causes this problem? How does the final HTML code
for such a link look? Do you see something like

<a href="./?a=1&amp;amp;B=2">foo</a>

Notice the "double-encoding" of the ampersand. This could be one reason
for your problem.

>Is there any other way other than
>looping and stripping the 'amp;' part prior to actually looking for
>parameters? What do others do in this situation?

Nothing, because it shouldn't happen.

Micha

Posted by The KwikOne on July 22, 2008, 5:01 pm
Please log in for more thread options
> .oO(The KwikOne)
>
> >Since to have a page validate (HTML and XHTML) you should have your
> >URL parameters separated by the appropriate separator. However, if an
> >ampersand is used it needs to be expressed as &amp; (example: ./
> >index.php?a=3D1&amp;B=3D2).
>
> You only do this if the URL is printed to an HTML page, for example in
> an 'a' element:
>
> <a href=3D"./?a=3D1&amp;B=3D2">foo</a>
>
> BTW: Don't write "index.html" or "index.php" in URLs, it's not necessary
> and bad style.
>
> >But, if that is done, then the _GET or
> >_REQUEST array element names are incorrect.
>
> No. The &amp; is interpreted by the browser, the server will never see
> it if you click that link.
>
> >In the example the _GET
> >array will be:
> >_GET['amp;a'] =3D 1 (instead of _GET['a'] =3D 1) and _GET['amp;B'] =3D 2
> >(instead of _GET['B'] =3D 2).
>
> >So, how do I get around this?
>
> There's a bug somewhere in your code. Can you post a short code example
> or page snippet which causes this problem? How does the final HTML code
> for such a link look? Do you see something like
>
> <a href=3D"./?a=3D1&amp;amp;B=3D2">foo</a>
>
> Notice the "double-encoding" of the ampersand. This could be one reason
> for your problem.
>
> >Is there any other way other than
> >looping and stripping the 'amp;' part prior to actually looking for
> >parameters? What do others do in this situation?
>
> Nothing, because it shouldn't happen.
>
> Micha

Micha,
Actually I found that this problem only occurred when doing a
window.open in javascript;
such as window.open('/x.php?a=3D1&amp;b=3DB', etc);
So, I have found my workaround (personally I think it is a bug within
javascript in Firefox v3
since it did not seem to see failures when IE v7 was used).
So, instead of window.open('/x.php?a=3D1&amp;b=3DB', etc);
I now have it as: window.open('/x.php?a=3D1&'+'b=3DB', etc);
and it works OK and validation does not fail.

Posted by John Dunlop on July 23, 2008, 5:06 am
Please log in for more thread options
The KwikOne:

> Actually I found that this problem only occurred when doing a
> window.open in javascript;
> such as window.open('/x.php?a=1&amp;b=B', etc);

Context is everything. Character references are not recognised in the
script element, so the "amp;" is part of the URL. Compare attributes
such as href, in which character references are recognised. See HTML
4.01 sec. 6.2:

http://www.w3.org/TR/html401/types.html#type-cdata

> So, I have found my workaround (personally I think it is a bug within
> javascript in Firefox v3
> since it did not seem to see failures when IE v7 was used).

Firefox gets it right; Internet Explorer gets it wrong.

--
Jock

Similar ThreadsPosted
anything incorrect? May 28, 2007, 2:05 pm
Incorrect result April 29, 2005, 2:06 pm
Incorrect path order for php.ini May 11, 2005, 11:06 pm
How to count lines in a file that meet criteria? July 14, 2004, 9:24 pm
PHP_SELF incorrect on WIMP shared host January 30, 2005, 5:53 pm
Passing parameter to PHP/cgi August 10, 2004, 2:05 am
Default parameter November 15, 2004, 5:10 pm
add parameter to all URLs December 14, 2004, 4:20 pm
Passing parameter from non-PHP-program to PHP/cgi August 12, 2004, 11:30 pm
Passing parameter from a non-PHP-program to PHP/cgi August 12, 2004, 11:36 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap