Hello, a few of you have been wondering how I made my signature like this:
Before you start, let me tell you that this is not the person viewing the image's IP, but the person who previously viewed the image's IP.
Well, first let me tell you that this is not infact a .png, .jpg or any other format of image, but it is a .php file, titled index.php.
So to start, make 2 files. 1 titled index.php and the other titled store.txt. Make sure both of these files are blank (0 bytes) and that they are in the same directory/folder. Open up index.php notepad, or any other editor.
I'm going to split up the index.php file into 3 parts for you. The first part is this:
Code:
<?
header("Content-type: image/png");
$store = "store.txt";
$fh = fopen($store, 'r');
$fs=filesize($store);
$output = fread($fh, $fs);
fclose($fh);
The first line with a <? in it just tells the server that it's a php file it's reading, and not an html file or something. This is required in all php documents.
The second line is telling the server it's an image and not just plain text.
The next few lines tells the server to open up the store.txt file and read it's contents. It then puts the data in the store.txt (in this case an IP) file into a variable, in this case $output. After it has done that, it closes the file. You don't have to close the file, but you should do it because it will decrease the load on the server quite a bit.
Our next step is to take the information stored in $output.php and make it into an image. This is the fun part.
Now, moving on to the next part of the index.php file:
Code:
$number = strlen($output);
$number = ($number*7)+9;
$im = imagecreate($number, 24);
$color1 = imagecolorallocate($im, 245, 245, 255);
$color2 = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 3, 5, 5, $output, $color2);
imagepng($im);
imagedestroy($im);
This is where we are actually creating the image. Basically we are taking whatever $output contains, and putting it onto a simple image. You can control what the background and text color of the image are by modifying $color1 and $color2.
$color1 is the background, in RGB (Red, Green, Blue) format. In this case, I just made it the color of the iPH background, which is 245, 245, 255 (if you want different colors, you can get them in Photoshop). $color2 is the font color, in this case black, or 0, 0, 0.
So all in all, it is taking the contents of the store.txt file, and putting them on an image. If that's all you wanted it to do, you could just make 1 more line at the end just containing ?> (but don't do that), to end the php. But let's take it 1 step further.
The third and final piece of code in index.php is going to get the IP of the user and put it into the store.txt file along with some other text.
Code:
$ip = $_SERVER['REMOTE_ADDR'];
$text = "Last IP that saw this image: " . $ip . " --H3X";
$store = "store.txt";
$fh = fopen($store, 'w');
fwrite($fh, $text);
fclose($fh);
?>
The first line is getting the ip with $_SERVER['REMOTE_ADDR'] and setting it to the variable $ip.
The next line is the text that is going to be on our image. Basically we are just taking the text "Last IP that saw this image: " and " --H3X" and putting the IP that we got on the line above and storing it into the variable $text.
Then, it writes the data stored in $text to store.txt, overwriting everything in there.
We then close up index.php with ?> to tell the server that the script is done.
So heres all the code above put together for the cheaters who don't read the tutorial and just want the code

.
Code:
<?
header("Content-type: image/png");
$store = "store.txt";
$fh = fopen($store, 'r');
$fs=filesize($store);
$output = fread($fh, $fs);
fclose($fh);
$text = $output;
$number = strlen($text);
$number = ($number*7)+9;
$im = imagecreate($number, 24);
$colour1 = imagecolorallocate($im, 245, 245, 255);
$colour2 = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 3, 5, 5, $text, $colour2);
imagepng($im);
imagedestroy($im);
$ip = $_SERVER['REMOTE_ADDR'];
$text = "Last IP that saw this image: " . $ip . " --H3X";
$store = "store.txt";
$fh = fopen($store, 'w');
fwrite($fh, $text);
fclose($fh);
?>
The store.txt file we created earlier we don't need to edit.
The next step is to sign upfor free hosting. I used arenaspace.com.
After you have signed up there, go to your setting and create a new subdomain, the name doesn't matter. Now go to the upload page and click on your subbdomain. Finally, just upload the 2 files you made. Now go to your URL bar and type in the subdomain you made, for example mine is h3x.awardspace.com.
You should have an image like mine. Now, to put it in your sig or put it on any webpage, just treat it as a normal image, and enter it's url. The first time you visit it, there will appear to be a fake image. This is because there is no data in store.txt. Just hit refresh, and everything will work. This only happens once, don't worry.
Hope you liked this tutorial.
If you want to show the person viewing the images IP, and not the person who just previously viewed the image's IP, replace the code in index.php with this: Code:
<?
header("Content-type: image/png");
$ip = $_SERVER['REMOTE_ADDR'];
$output = "Your IP: " . $ip . " --H3X";
$number = strlen($output);
$number = ($number*7)+9;
$im = imagecreate($number, 24);
$colour1 = imagecolorallocate($im, 245, 245, 255);
$colour2 = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 3, 5, 5, $output, $colour2);
imagepng($im);
imagedestroy($im);
?>
Pretty cool, eh?
Leave feedback please.