Page 1 of 1
does anyone know how?
Posted: Fri Nov 21, 2003 1:49 pm
by srgnt
Hi, I am looking for code that will generate an image and show the person whos viewing its ip address but i wanna use it in a forum so i want it to be like <img src="ip.php">... anyone have this code or know how to do it?
thanks
justin

Posted: Fri Nov 21, 2003 2:01 pm
by DuFF
Generating Images:
http://www.php.net/manual/en/ref.image.php
http://hotwired.lycos.com/webmonkey/01/ ... rogramming
http://www.devarticles.com/art/1/22
Get an IP address:
$ip = getenv("REMOTE_ADDR");
Found this in the comments of getenv() on php.net:
Code: Select all
<?php
function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";
return $ip;
}
?>
Posted: Fri Nov 21, 2003 2:08 pm
by microthick
http://www.danasoft.com/
also offers a free service you can use on forums. Not overly customizable, but it's an option if you don't wanna code.
Posted: Fri Nov 21, 2003 2:10 pm
by srgnt
how would i put them together... im fairly new php

Posted: Fri Nov 21, 2003 2:14 pm
by srgnt
ya... but i want mine on my server :-/ i thought about it tho
Posted: Fri Nov 21, 2003 2:14 pm
by d3ad1ysp0rk
by reading the generating images links
and putting the IP grabbing code above the image generation code, and using the $ip variable (or w/e u named it) for the text
Posted: Fri Nov 21, 2003 2:26 pm
by srgnt
ok so do somthing like this?:
Code: Select all
<?php
function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
else $ip = "UNKNOWN";
return $ip;
}
header("Content-type: image/jpeg");
$width = 500;
$height = 20;
$image = imagecreate($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$green = imagecolorallocate($image, 0, 255, 0);
if (!isset($text)) {
$text = "use querystring '?text=$ip'";
}
imagefilledrectangle($image, 0, 0, $width, $height, $black);
imagettftext($image, 20, 0, 0, 15, $green, "OCRAEXT.TTF", $text); // (any) .ttf file required
ImageJPEG($image);
imagedestroy($image);
?>
Posted: Fri Nov 21, 2003 2:41 pm
by vigge89
yes, that would work i think
Posted: Fri Nov 21, 2003 2:51 pm
by srgnt
ok i tried that but doesnt work when i link it as an image and when i type in the url it gives me this error:
<br/>
<b>Fatal error</b>: Call to undefined function: imagecreate() in <b>/home/pridebmx/public_html/ip.php</b> on line <b>15</b><br/>
any ideas?
Posted: Fri Nov 21, 2003 3:03 pm
by DuFF
I don't think you have GD installed, and therefore can't use the image functions. The second tutorial I posted goes over how to install GD into your server.
Check out these 2 links:
Tutorial:
http://hotwired.lycos.com/webmonkey/01/ ... rogramming
Easy Installer for GD and other things:
http://php.weblogs.com/easywindows