php: Showing client information in PNG file
Posted: Mon Oct 20, 2003 10:20 am
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]
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]