Jump to content

How to make a dynamic signature (IP sig)


gamehead200

Recommended Posts

EDIT:

For everyone's benefit, I have released my original "Jeremy" signature (i.e., the source code, graphics, etc.) under a GPL license. Use it as you wish. :) Grab it here!

-----

For this tutorial, the server you will be using MUST have Apache and the GD plugin for PHP installed. You must have some experience using PHP. We will start by opening Notepad (or your favourite text editor) and creating a new file called .htaccess. The name of the signature we will be using will be mysig.jpg.

In the .htaccess file, put the following:

<Files mysig.jpg>
ForceType application/x-httpd-php
</Files>

This will tell the server to parse the mysig.jpg file as a PHP file. Save this file in a folder where you will also place the other files.

Now, open your text editor and create your signature file, mysig.jpg. Put the following in it:

<?php
Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// set the dimensions
$img_width = 240;
$img_height = 25;

// create the image
$image = imagecreate($img_width, $img_height);

// set the colours
$cool  = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red   = imagecolorallocate($image, 255, 0, 0);
$grey  = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue  = imagecolorallocate($image, 0, 0, 255);

// set the background colour
// number or is top left pixel x, top left pixel y, bottom right pixel x, bottom right pixel y
imagefilledrectangle($image, 0, 0, $img_width, $img_height, $cool);

// set the font and print text
$font = '/path/to/your/ttf/font/verdana.ttf';

// now i will create a line with font size 8, with no angle, 10 pixels to the right, and 17 pixels down
ImageTTFText ($image, 8, 0, 10, 17, $white, $font, "Your IP Address is... ".$REMOTE_ADDR);

// the above will display your IP address

// output and destroy
imagepng($image);
imagedestroy($image);

?>

If you don't want the server to create the image for you, you can always create an image in Photoshop and use it as your background.

<?php
Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// create the image using your own background
$image = imagecreatefromjpeg("background.jpg");

// dimensions of the image used
$img_width = 240;
$img_height = 25;

// set the colours
$cool  = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red   = imagecolorallocate($image, 255, 0, 0);
$grey  = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue  = imagecolorallocate($image, 0, 0, 255);

// set the font and print text
$font = '/path/to/your/ttf/font/verdana.ttf';

// now i will create a line with font size 8, with no angle, 10 pixels to the right, and 17 pixels down
ImageTTFText ($image, 8, 0, 10, 17, $white, $font, "Your IP Address is... ".$REMOTE_ADDR);

// the above will display your IP address

// output and destroy
imagepng($image);
imagedestroy($image);

?>

Those are the basics. You can do so much with PHP!

Want to use a hit counter for your sig? Use this piecee of code in your signature:

// counter - CHMOD your counter file to 777
$viewss = file("/path/to/your/counter/file/views.txt");
$views = $viewss[0]; $views++;
$fp = fopen("/path/to/your/counter/file/views.txt", "w");
fwrite($fp, $views);
fclose($fp);
$counter = "$views people viewed this since 11/5/03!";

Want a different message to appear everytime your sig is loaded? Use this in your code:

// set quote file
$quotes = file('quotes.txt');
$quote = array_rand($quotes);

$joke = wordwrap($quotes[$quote], 60, "\n", 1);
$joke = explode("\n", $joke);

// this part goes where the rest of the output is done
for($i=0; $i<count($joke); $i++) {
ImageTTFText ($image, 8, 0, 14, (23+($i*15)), $white, $font, $joke[$i]);
}

Want to output someone's browser, IP, and resolved IP? Use this in your code:

// get IP and resolve IP
$ip = $REMOTE_ADDR;
$resolved = gethostbyaddr ($REMOTE_ADDR);

// check for non resolve of IP and rip domain if resolved
if ($resolved == $ip) {
$isp = ".. Can't Resolve IP";
}
else
{
$str = preg_split("/\./", $resolved);
$i = count($str);
$x = $i - 1;
$n = $i - 2;
$isp = $str[$n] . "." . $str[$x];
}

// Simple OS Detection
$os = $HTTP_USER_AGENT;
$oslist = Array (

// Windows
"Win|Windows",
"Win16|Windows",
"Win95|Windows 95",
"Win98|Windows 98",
"WinME|Windows ME",
"Win32|Windows",
"WinNT|Windows NT",
"Windows 3.1|Windows 3.1",
"Windows 95|Windows 95",
"Windows CE|Windows CE",
"Windows 98|Windows 98",
"Windows ME|Windows ME",
"Windows NT|Windows NT",
"Windows NT 5.0|Windows 2000",
"Windows NT 5.1|Windows XP",

// Macintosh
"Mac_68000|MacOS m68K",
"Mac_68K|MacOS m68K",
"Mac_PowerPC|MacOS PPC",
"Mac_PPC|MacOS PPC",
"Macintosh|MacOS",

// Unices
"X11|UNIX",
"BSD|BSD",
"SunOS|SunOS",
"IRIX|IRIX",
"HP-UX|HP-UX",
"AIX|AIX",
"QNX|QNX",
"SCO_SV|SCO UNIX",
"FreeBSD|FreeBSD",
"NetBSD|NetBSD",

// Linux
"Linux|Linux",
"Debian|Debian GNU/Linux",

// Other
"BeOS|BeOS",
"OS/2|OS/2",
"AmigaOS|AmigaOS",

);

foreach ($oslist as $osnow) {
$osnow = explode ("|", $osnow);
if (eregi ($osnow[0], $os)) {
$endos = $osnow[1];
$check = "No";
} elseif ($check != "No") {
$endos = "Unknown";
}
}

/*
to output the OS, use $endos
to output the IP, use $ip
to output the resolved IP, use $resolved
*/

Want to output someone's browser? Use this code:

//browser type
  $agent = $HTTP_USER_AGENT;
  if ( strstr($agent, "MSIE 5") ) $browser = "using IE 5";
  elseif ( strstr($agent, "MSIE 6") ) $browser = "using IE 6";
  elseif ( strstr($agent, "MSIE 4") ) $browser = "using IE 4";
  elseif ( strstr($agent, "Firebird") ) $browser = "using Firebird";
  elseif ( strstr($agent, "Safari") ) $browser = "using Safari";
  elseif ( strstr($agent, "Mozilla/5") ) $browser = "using Mozilla/Netscape 5";
  elseif ( strstr($agent, "Mozilla/6") ) $browser = "using Netscape 6";
  elseif ( strstr($agent, "Mozilla/4") ) $browser = "using Netscape 4";
  elseif ( strstr($agent, "Opera") ) $browser = "using Opera";
  else $browser = "";

// to output the browser, use $browser

Want to use a different background everytime? Use this code:

// random background

$random_image = array("",
                  "bg1.jpg",
                  "bg2.jpg",
                  "bg3.jpg",
                  "bg4.jpg");

srand ((double) microtime() * 1000000);
$rnd = rand(1,4);

// create the image
$image = imagecreatefromjpeg($random_image[$rnd]);

Good luck to all coders! Any comments, suggestions, and questions are appreciated! :)

:thumbup

NOTE: I have attached a sample mysig.jpg and .htaccess file.

sample.zip

Link to comment
Share on other sites


Ok, first attempt, and so far no go.

The .htaccess file is inside the Signature folder, the file as you can tell is named mysig.jpg

Now I have GD plugin and the latest apache... I know this because I use GD for another part of my website... and it works perfectly...

http://www.cyberpawz.com/signature/mysig.jpg

As you can tell below where I placed the image tags nothing shows up... any help would be appreciated. I changed the font to

$font = '/Volumes/Server/htdocs/Signature/Caleu.ttf';

Now don't forget I'm on a Mac, but as far as I can tell if I put the font in the same folder as the signature is in, and just cut that down to:

$font = /Caleu.tiff

Wouldn't that work as well, or does the font need to be active in the system?

mysig.jpg

Link to comment
Share on other sites

OK, when I opened up the link in IE, I realized that all of your code was showing. The server is not parsing the file as a PHP file either because there's a configuration problem or because you did not put the .htaccess file.

If you go into your terminal and ls the Signature folder, what files show up? :}

Most of the time, it doesn't matter how you tell the server where your font file is... But, its usually better to include the whole path... :)

BTW, open up your mysig.jpg file and make sure you save it as just Text. You have random letters with accents everywhere...

Example:

$blue Ê= imagecolorallocate($image, 0, 0, 255);

Try using the sample files I just uploaded. :)

Link to comment
Share on other sites

OK, when I opened up the link in IE, I realized that all of your code was showing.  The server is not parsing the file as a PHP file either because there's a configuration problem or because you did not put the .htaccess file.

If you go into your terminal and ls the Signature folder, what files show up? :}

Most of the time, it doesn't matter how you tell the server where your font file is... But, its usually better to include the whole path... :)

BTW, open up your mysig.jpg file and make sure you save it as just Text.  You have random letters with accents everywhere...

Example:

$blue Ê= imagecolorallocate($image, 0, 0, 255);

Try using the sample files I just uploaded. :)

I copy and pasted the information above... dang it...

and the .htaccess file is there, I know it is cause I can edit it...

I'll try again.

Link to comment
Share on other sites

Still not working, hell if I know what is going on. I am using 10.4 for the Mac OS, when I save this I'm using BBEdit Light...

Unless bbedit light 6.1.2 is the reason for the bad code I'm clueless...

And for the record if I go through the terminal and look at the folder's innards... everything is there.

At least all that should be.

Link to comment
Share on other sites

Still not working, hell if I know what is going on.  I am using 10.4 for the Mac OS, when I save this I'm using BBEdit Light...

Unless bbedit light 6.1.2 is the reason for the bad code I'm clueless...

And for the record if I go through the terminal and look at the folder's innards... everything is there.

At least all that should be.

OK... Do the following:

Create a PHP file called phpinfo.php and put the following code in it:

<?php phpinfo(); ?>

Then post the link to this PHP file so I can take a look at what it outputs. :)

Link to comment
Share on other sites

Still not working, hell if I know what is going on.  I am using 10.4 for the Mac OS, when I save this I'm using BBEdit Light...

Unless bbedit light 6.1.2 is the reason for the bad code I'm clueless...

And for the record if I go through the terminal and look at the folder's innards... everything is there.

At least all that should be.

OK... Do the following:

Create a PHP file called phpinfo.php and put the following code in it:

<?php phpinfo(); ?>

Then post the link to this PHP file so I can take a look at what it outputs. :)

already had it... www.cyberpawz.com/test.php

Link to comment
Share on other sites

I don't see anything wrong with your configuration... Try getting rid of those weird characters in your code... :wacko:

The issue is that what I am working on the code on the computer, there are no errors... it's after it's saved... which I don't understand how since I am saving it as a generic text format...

I'm lost, and somewhat confused on what this is happening at all...

This is what I see when I edit and save it as a pure txt format...

code.jpg

Link to comment
Share on other sites

Ok, no go... and I downloaded the file you had on the first page to see if I made a mistake or no. And so far no go.

mysig.jpg

This is the code in it:

<?php

Header ('Content-type: image/jpeg');

Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');

Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');

Header('Pragma: no-cache');

// set the dimensions

$img_width = 240;

$img_height = 25;

// create the image

$image = imagecreate($img_width, $img_height);

// set the colours

$cool  = imagecolorallocate($image, 81, 86, 96);

$black = imagecolorallocate($image, 0, 0, 0);

$white = imagecolorallocate($image, 255, 255, 255);

$red   = imagecolorallocate($image, 255, 0, 0);

$grey  = imagecolorallocate($image, 204, 204, 204);

$green = imagecolorallocate($image, 206, 129, 18);

$blue  = imagecolorallocate($image, 0, 0, 255);

// set the background colour

// number or is top left pixel x, top left pixel y, bottom right pixel x, bottom right pixel y

imagefilledrectangle($image, 0, 0, $img_width, $img_height, $cool);

// set the font and print text

$font = '/Volumes/Server/htdocs/Signature/TAGSXTREME.TTF';

// now i will create a line with font size 8, with no angle, 10 pixels to the right, and 17 pixels down

ImageTTFText ($image, 8, 0, 10, 17, $white, $font, "Your IP Address is... ".$REMOTE_ADDR);

// the above will display your IP address

// output and destroy

imagepng($image);

imagedestroy($image);

?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...