$_GET['q'] does not work with & ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

$_GET['q'] does not work with & ??

Post by nicosns »

I tried to get the id info from http://www.domain.com/profile.php?id=v-&-cat but I only see the 'v-'

The codes I tried

Code: Select all

<?= htmlentities($_GET['id']) ?>
and

Code: Select all

<?php echo $_GET['id'] ?>
Is this normal? And if so, how to fix this? thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: $_GET['q'] does not work with & ??

Post by requinix »

htmlentities works, but you have to use it on the link. By the time your other script gets it it's too late.

Code: Select all

// bad
echo "http://www.domain.com/profile.php?id=v-&-cat";
 
// good
echo "http://www.domain.com/profile.php?id=" . htmlentities("v-&-cat");
htmlspecialchars is okay, but if you want to follow standards htmlentities is better.
nicosns
Forum Newbie
Posts: 21
Joined: Thu Jun 21, 2007 1:53 pm

Re: $_GET['q'] does not work with & ??

Post by nicosns »

thank you, tasairis!
Post Reply