Skip to content

Instantly share code, notes, and snippets.

@csf30816
Created June 16, 2017 02:07
Show Gist options
  • Save csf30816/ace7143e211cb899908c50ca0df50b13 to your computer and use it in GitHub Desktop.
Save csf30816/ace7143e211cb899908c50ca0df50b13 to your computer and use it in GitHub Desktop.
Creates a simple PHP IP image
<?php
// Function to get the client IP address
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, get_client_ip(), $text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>
@csf30816
Copy link
Author

@ateesdalejr I am guessing you are who I think you are so Your Welcome :)

@prail
Copy link

prail commented Jun 16, 2017

yup I'm @theultimatum I just recently changed my git username.

@bob1171
Copy link

bob1171 commented Sep 20, 2017

how do u host php on the scratch forums?

@prail
Copy link

prail commented Oct 12, 2017

@bob1171 You can't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment