Sinisterly
Simple PHP image generation - show a user the IP address used to grab the image - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: Simple PHP image generation - show a user the IP address used to grab the image (/Thread-Simple-PHP-image-generation-show-a-user-the-IP-address-used-to-grab-the-image)



Simple PHP image generation - show a user the IP address used to grab the image - Xeru - 01-12-2015

The greatest purpose I've found for this is scaring people into thinking their IP address was logged after sending them an image that looks illegal, but I think it can be repurposed for other fun stuff. I saw a thread in another page about generating a fake 'image' with mod_rewrite that LOGS the IPs, but it doesn't return an actual image so it's kind of stupid in my opinion.

You can add this to a script that logs the IP address if you want, just include() this class.
This is kind of just code, but it also has explanation to help set it up correctly.

PHP Code:
<?php $img = imagecreate( 200, 30 ); // 200x30 resolution of the image $background = imagecolorallocate( $img, 0, 0, 0 ); // set the background color in RGB $text_colour = imagecolorallocate( $img, 255, 0, 0 ); // set the text color in RGB $line_colour = imagecolorallocate( $img, 255, 0, 0 ); // set the color of the line below the text in RGB imagestring( $img, 4, 4, 4, $_SERVER['REMOTE_ADDR']." logged", $text_colour ); // adds the text to the image, $_SERVER['REMOTE_ADDR'] is the user's IP address. This returns the IP followed by "logged" imagesetthickness ( $img, 5 ); // Sets the thickness of the line imageline( $img, 0, 25, 200, 25, $line_colour ); // Draws the line, with coordinates and color header( "Content-type: image/png" ); // Content type tells the browser how to show the data imagepng( $img ); // Makes the image a PNG image type // The next lines just finish up the job imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $img ); // image is kill ?>

To have this work and look like a normal .png link as you would want it to, you need to rewrite a .png extension to the php file this code is in.

Lastly, you need to install php5 GD for image generation.
To install GD on your system, use one of these (depending on package manager)
apt-get install php5-gd
pacman -S php-libgd
yum install php5-gd

(thanks @phyrrus9 )

This isn't exactly advanced by any means, it's pretty basic; but for beginners it might be a nice thing to look at or utilize.
I hope someone finds this useful, all feedback is appreciated.


RE: Simple PHP image generation - show a user the IP address used to grab the image - phyrrus9 - 01-12-2015

apt-get install php5-gd
pacman -S php-libgd
yum install php5-gd