Forum Moderators: coopster

Message Too Old, No Replies

Getting GET to work with &

Trying to get a page to validate

         

RandallK

7:53 pm on Feb 5, 2010 (gmt 0)

10+ Year Member



Attempting to get a page to validate so I am trying to properly deal with ampersands.

example.com/product.php?cat=10&display=ALL&name=title

I changed the & to & amp; (no space) and it appears the $_GET['display'] is not working, if I delete the amp; part, everything displays as expected again.

Any advice would be greatly appreciated. Everywhere I look says just add amp; and life will be fine...

Readie

9:04 pm on Feb 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why don't you do a .htaccess rewrite to cleanse the URL? Then you wouldn't need to deal with the ampersands at all.

londrum

9:16 pm on Feb 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



just changing it to
& amp;
shouldn't make
GET['display']
not work. it must be something else in your script.

maybe you're encoding the url somewhere, and changing
& amp;
into
& amp; amp;
.

if that was happening before then you wouldn't have noticed, because changing
&
into
& amp;
would be okay.

[p.s. for the mods... someone needs to fix this new webmasterworld bug that stops & amp; displaying correctly when you type it!]

RandallK

9:52 pm on Feb 5, 2010 (gmt 0)

10+ Year Member



In theory, if the URL is displayed in the browser with the & and I were to go into the address bar and change that & to & amp;... that should really have no effect right? It should work exactly the same both ways... right?

But in my case it is not... can't figure out why. Not going to stress over it... but I think its important to understand the reasons things happen. I may rewrite the URL eventually, but I want to understand why I've got this issue.

rocknbil

11:34 pm on Feb 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I were to go into the address bar and change that & to & amp;... that should really have no effect right?


No . . . from the address bar,

script.php?var1=abc&var2=def

(in theory) will get parsed as

var1 : abc
amp;var2 : def

In reality, something may be done with the ; to blow that out of the water . . . in any case, when you use entities in HTML pages/script output, and a link is clicked, it is converted to an & by the browser. So if you put it in the address bar, it will be sent as a literal.

If you have this in your script, or are building a string

script.php?var1=abc&var2=def

Dig around for htmlentities(), you're likely applying htmlentities to it and getting

script.php?var1=abc&var2=def

But if you view source, you'll spot it. When the first one is clicked, it displays in the address bar as

script.php?var1=abc&var2=def


[p.s. for the mods... someone needs to fix this new webmasterworld bug that stops & amp; displaying correctly when you type it!]


Which is, I think, exactly what's going on w. Randallk, inversed. :-) Bug reported [webmasterworld.com], it does it with   too.

But Bill, why's it not doing it with your &? Once you figger out what it's doing, it's not that difficult to game. :-) But if they fix it, all my posts with these will be hosed up . . .

RandallK

12:02 am on Feb 6, 2010 (gmt 0)

10+ Year Member



So dumb question... how does one get it to validate?

Do I need to run it through htmlentities?

rocknbil

3:40 am on Feb 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Right, but make sure it's on raw data, not something already converted to entities. That is, if you already have & in a string, htmlentities will just turn the & to & . . . again.

View your source code on a page that's getting errors from ampersands. Remember the way it renders in the page is not always what's in the source code. If you mouseover a link and see this,

script.php?var1=abc&var2=def

when you view source, you **should** see this.

script.php?var1=abc&var2=def

But put that second one in the address bar and it breaks it.