does anyone know how?

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
srgnt
Forum Newbie
Posts: 5
Joined: Fri Nov 21, 2003 1:49 pm

does anyone know how?

Post 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 :wink:
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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;
}
?>
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post 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.
srgnt
Forum Newbie
Posts: 5
Joined: Fri Nov 21, 2003 1:49 pm

Post by srgnt »

DuFF wrote: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;
}
?>
how would i put them together... im fairly new php :oops:
srgnt
Forum Newbie
Posts: 5
Joined: Fri Nov 21, 2003 1:49 pm

Post by srgnt »

ya... but i want mine on my server :-/ i thought about it tho
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
srgnt
Forum Newbie
Posts: 5
Joined: Fri Nov 21, 2003 1:49 pm

Post 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); 

?>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

yes, that would work i think
srgnt
Forum Newbie
Posts: 5
Joined: Fri Nov 21, 2003 1:49 pm

Post 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?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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
Post Reply