Jump to content


Photo

IP Address/Image Combo


  • Please log in to reply
5 replies to this topic

#1 chris collins

chris collins
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 April 2006 - 12:39 AM

I am looking for a way to assign a unique image for each unique IP that visits my site, and display it on the page. This should be easy, correct? Of course, I am a newbie, so I wouldn't know. If someone could point me in the right direction :)

Chris

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 15 April 2006 - 12:57 AM

If you are merely assigning images to predefined IP's (You already know the IP's you will be assigning the images to) then yes, it is very easy. Paste your code here and maybe we can help you implement it into your existing site. You can do this using only PHP...or you can use PHP/MySQL. Depends on how your site is set up and how you manage your site's visitors.
PHP Ninja

#3 chris collins

chris collins
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 April 2006 - 01:18 AM

[!--quoteo(post=364959:date=Apr 14 2006, 07:57 PM:name=Caesar)--][div class=\'quotetop\']QUOTE(Caesar @ Apr 14 2006, 07:57 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
If you are merely assigning images to predefined IP's (You already know the IP's you will be assigning the images to) then yes, it is very easy. Paste your code here and maybe we can help you implement it into your existing site. You can do this using only PHP...or you can use PHP/MySQL. Depends on how your site is set up and how you manage your site's visitors.
[/quote]

Right, I will have predefined IP's that I will be using. I really haven't created any code yet. I plan to display the images into table cells or something. I'd rather use only PHP if possible, although I can create a database if necessary....

#4 chris collins

chris collins
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 April 2006 - 04:23 PM

OK here is the script I want to use, if possible:

<?php
$img_number = imagecreate(275,25);
$backcolor = imagecolorallocate($img_number,102,102,153);
$textcolor = imagecolorallocate($img_number,255,255,255);

imagefill($img_number,0,0,$backcolor);
$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

and it is called with this:

<img src="http://yoursite/image.php" border="1">

Instead of displaying the IP of the person viewing the page (which I want it to do as well), I want each IP associated with a picture, which I will set up. What do you all think?

Chris

#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 15 April 2006 - 04:41 PM

you could have an array of IP's/images. so:


<?php
// extend this array for all your ip's+corresponding images.
$ip2img = array("123.456.789.012"=>"an_image.jpg", "200.123.150.234"=>"another_image.jpg");

$ip = $_SERVER['REMOTE_ADDR'];
$file = $ip2img[$ip];

$img_number = imagecreatefromjpeg($file);

$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

obviously this is not exactly how you want the code, as i'm not 100% sure what you need, but it should get you started.
cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#6 chris collins

chris collins
  • Members
  • Pip
  • Newbie
  • 4 posts

Posted 15 April 2006 - 05:16 PM

[!--quoteo(post=365111:date=Apr 15 2006, 11:41 AM:name=redbullmarky)--][div class=\'quotetop\']QUOTE(redbullmarky @ Apr 15 2006, 11:41 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
you could have an array of IP's/images. so:
<?php
// extend this array for all your ip's+corresponding images.
$ip2img = array("123.456.789.012"=>"an_image.jpg", "200.123.150.234"=>"another_image.jpg");

$ip = $_SERVER['REMOTE_ADDR'];
$file = $ip2img[$ip];

$img_number = imagecreatefromjpeg($file);

$number = " Your IP is $_SERVER[REMOTE_ADDR]";

Imagestring($img_number,10,5,5,$number,$textcolor);

header("Content-type: image/jpeg");
imagejpeg($img_number);
?>

obviously this is not exactly how you want the code, as i'm not 100% sure what you need, but it should get you started.
cheers
Mark
[/quote]


Thanks Mark, I'll see what I can do with that :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users