views:

50

answers:

3

I think I'm doing this wrong but this is what I have...

if($_GET['color']) {
    $color = "signature_";
echo "<img src=\"/images/+ $color \"; \"class=\"border\" alt=\"\" />";

What I'm trying to do is output the colored image based on the users input.

So say this is what I am doing.

Http://somedomain.com/index.php?username=Ultima&amp;color=red.

So far I am displacing usernames properly, but images are not working.

I used "signature_" as a prefix because the image colors are all prefixed with that.

The images I'm trying to display upon input:

signature_red.png
signature_green.png
signature_white.png
signature_yellow.png
signature_gold.png
signature_silver.png
signature_purple.png
signature_pink.png

__

I'm not sure what I'm doing wrong with my code... but does anyone know how I could display the proper images upon url input using $get['color']?

+1  A: 

Unless i'm being stupid (which is entirely possible), this bitneeds changing:

if($_GET['color']) {
    $color = "signature_";

should be

if($_GET['color']) {
  $color = "signature_" . $_GET['color'];

and it needs to validate the colour as well, someone else has covered that.

benlumley
+3  A: 
$g=$_GET['color'];
if(in_array($g, array('red', 'pink', 'yellow' etc...))) {
    $color = "signature_".$g.'.png';
    echo '<img src="/images/'. $color.'" class="border" alt="" />';
}

Or something like that. You have to replace the "etc..." part.
Never put GET params into string without some check.

Vili
Thank you for giving me the extra added security check. =)
Ultima
A: 
$color = "signature_" . $_GET['color'] . ".png";
echo "<img src=\"/images/$color\" class=\"border\" alt=\"\" />";
Amarghosh