Connecting Tech Pros Worldwide Forums | Help | Site Map

Why doesn't variables work in image strings?

Ajm113's Avatar
Familiar Sight
 
Join Date: Jun 2007
Posts: 161
#1: Jun 21 '08
I want to create a image string that retrieves the params of the url to put on the image in php like so:

image.php?user=Ajm113

Then it should print the user on the image string, but for some reason it doesn't work. Is it more then that?

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#2: Jun 21 '08

re: Why doesn't variables work in image strings?


you need to $_GET['user'] to use the string.
Newbie
 
Join Date: Jun 2008
Posts: 25
#3: Jun 21 '08

re: Why doesn't variables work in image strings?


Try this:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $text = $_GET['user'];
  3.  
  4. $im = imagecreate(100, 20);
  5. $bg = imagecolorallocate($im, 200, 200, 200);
  6. $fg = imagecolorallocate($im, 0, 0, 255);
  7.  
  8. imagestring($im, 3, 5, 3, $text, $fg);
  9.  
  10. header("Content-type: image/png");
  11. imagepng($im);
  12. ?>
  13.  
call the script with something like image.php?user=myusername
Reply