Page 1 of 1

php: Showing client information in PNG file

Posted: Mon Oct 20, 2003 10:20 am
by Deimos
php: This script creates an easy .png file of the clients information. The way it's scripted now, you should include it as an image.



If you call it php2png.php

Example: <img src="php2png.php" />



[php]<?php



//This script is copyrighted by Deimos.

//For questions mail deimos@aq2world.net



//Take a look at http://www.aq2world.net





header ("Content-type: image/png");



$UserAgent = $_SERVER['HTTP_USER_AGENT'];



$Platform = "This platform is not recognized";



if(strstr($UserAgent, 'Win')){

$Platform = 'Windows';

}else if(strstr($UserAgent, 'Mac')){

$Platform = 'Macintosh';

}else if(strstr($UserAgent, 'Linux')){

$Platform = 'Linux';

}else if(strstr($UserAgent, 'Unix')){

$Platform='Unix';

}



if(preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $UserAgent, $found) && strstr($UserAgent, "MSIE")){

$Browser = "Opera " . $found[1];

}else if(preg_match("/Opera ([0-9]\.[0-9]{0,2})/i", $UserAgent, $found) && strstr($UserAgent, "Mozilla")){

$Browser = "Opera " . $found[1];

}else if(preg_match("/Opera\/([0-9]\.[0-9]{0,2})/i", $UserAgent, $found)){

$Browser = "Opera " . $found[1];

}else if(preg_match("/Netscape[0-9]\/([0-9]{1,2}\.[0-9]{1,2})/i", $UserAgent, $found)){

$Browser = "Netscape " . $found[1];

}else if(preg_match("/Mozilla\/([0-9]{1}\.[0-9]{1,2}) \[en\]/i", $UserAgent, $found)){

$Browser = "Netscape " . $found[1];

}else if(preg_match("/MSIE ([0-9]{1,2})/i", $UserAgent, $found)){

$Browser = $found[0];

}else{

$Browser = $UserAgent;

}



if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]!=""){

$IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];

$Proxy = $HTTP_SERVER_VARS["REMOTE_ADDR"];

}else{

$IP = $HTTP_SERVER_VARS["REMOTE_ADDR"];

}



$Host = gethostbyaddr($IP);

$s = preg_split("/\./", $Host);

$i = count($s);

$x = $i - 1;

$n = $i - 2;

$ISP = $s[$n] . "." . $s[$x];





$s1 = "Your ip is " . $IP . " and your isp " . $ISP;

$s2 = "You are using " . $Platform . " and browsing with " . $Browser;



$w = strlen($s1) >= strlen($s2) ? strlen($s1) : strlen($s2);



if($Proxy){

$s3= "Through proxy " . $Proxy;

$w = $w >= strlen($s3) ? $w : strlen($s3);

$w = $w * imagefontwidth(3) + 20;

$im = @ImageCreate($w, 80) or die ("Cannot Initialize new GD image stream");

$background_color = ImageColorAllocate ($im, 255, 255, 255);

$text_color = ImageColorAllocate ($im, 0, 0, 255);

ImageString ($im, 3, 10, 30, $s1, $text_color);

ImageString ($im, 3, ($w / 2) - ((strlen($s2) * imagefontwidth(3)) / 2), 50, $s2, $text_color);

ImageString ($im, 3, ($w / 2) - ((strlen($s3) * imagefontwidth(3)) / 2), 70, $s3, $text_color);

ImagePng ($im);

}else{

$w = $w * imagefontwidth(3) + 20;

$im = @ImageCreate ($w, 60) or die ("Cannot Initialize new GD image stream");

$background_color = ImageColorAllocate ($im, 255, 255, 255);

$text_color = ImageColorAllocate ($im, 0, 0, 255);

ImageString ($im, 3, 10, 10, $s1, $text_color);

ImageString ($im, 3, ($w / 2) - ((strlen($s2) * imagefontwidth(3)) / 2), 30, $s2, $text_color);

ImagePng ($im);

}







?>[/php]

Posted: Mon Oct 20, 2003 1:02 pm
by Clown
Can someone do this so I can see it in action please?

Posted: Mon Oct 20, 2003 1:07 pm
by Den
Parse error: parse error in /var/www/****/html/php2png.php on line 25

Posted: Tue Oct 21, 2003 3:34 am
by Deimos

Posted: Tue Oct 21, 2003 5:13 am
by Clown
I don't see the point of that :)

Posted: Tue Oct 21, 2003 7:57 am
by Den
totally agree :) altho the image creating part is always fun to look at :)