how to perform this task?

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
hughr
Forum Newbie
Posts: 3
Joined: Sun Apr 18, 2004 7:31 am
Location: G.D.CHINA

how to perform this task?

Post by hughr »

i saw some pic on there .
can show you ip ,you location.
how to use php to perform this task?

regards
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

combo: imagecreate() and $_SERVER['REMOTE_ADDR']
User avatar
erikante
Forum Newbie
Posts: 8
Joined: Sat May 15, 2004 11:58 am
Location: NY

Post by erikante »

You need to download JPGraph first. then save the following code and include in your page. Works for me..Hope that helps.

Code: Select all

<?
include ("../jpgraph-1.15beta/src/jpgraph.php");	//you need to include these two files
include ("../jpgraph-1.15beta/src/jpgraph_canvas.php"); //you can download jpgraph from http://www.aditus.nu/jpgraph/
function getip() {
if (isSet($_SERVER)) {
 if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) {
  $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
 } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) {
  $realip = $_SERVER["HTTP_CLIENT_IP"];
 } else {
  $realip = $_SERVER["REMOTE_ADDR"];
 }

} else {
 if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
  $realip = getenv( 'HTTP_X_FORWARDED_FOR' );
 } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
  $realip = getenv( 'HTTP_CLIENT_IP' );
 } else {
  $realip = getenv( 'REMOTE_ADDR' );
 }
}
return $realip;
}


// Create the graph. 
$graph = new CanvasGraph(115,72,"auto");	
$ip=getip();
$t1 = new Text(" Your IP address\n $ip" );
$t1->Pos(0.05,0.15);
$t1->SetFont(FF_FONT1,FS_NORMAL);
$t1->SetBox("white","black",true);
$t1->ParagraphAlign("center");
$t1->SetColor("black");
$graph->AddText($t1);
$graph->Stroke();


?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

erikante wrote:You need to download JPGraph first.
...or if you prefer using [php_man]ImageTTFText[/php_man]:

Code: Select all

<?php
    $l = $_SERVER['REMOTE_ADDR'];
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
    header("Pragma: no-cache");
    header("Content-type: image/png");
    $img_handle = ImageCreate (500, 30) or die ("Cannot Create image");
    $back_color = ImageColorAllocate ($img_handle, 200, 200, 200);
    ImageTTFText ($img_handle, 14 / 96 * 72, 0, 20, 18, ImageColorAllocate ($img_handle, 0, 0, 0), dirname( __FILE__ )."/verdana.ttf",  $l);
    ImagePng ($img_handle);
?>
Not tested, but it should work and should be tweaked to fit your desired result.
Post Reply