Armored_Email_HOWTO.php
Sprache: English
Programmiersprache: PHP
Veröffentlicht von: linuxfutures [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1311
Beschreibung
Shows how to encapsulate emails into images, to reduce the effectiveness of scumsucking, spam puking robots that scan web pages for email addresses.
Code
1 <?php
2
3 // armored_email_HOWTO.php
4 // (c) 2000 LinuxFutures.com, Inc.
5 // Released under GNU Library Public License
6 // No Warranty.
7 // [Blatant Plug]. Dude!: Please visit our game site: www.linuxfutures.com
8 //
9 // DO NOT USE AS IS. Adapt to your purposes FIRST.
10 //
11 // WHAT IT DOES
12 // It doesn't prevent spam. It prevents text-scanning robots from grabbing
13 // the address off the page, because now it is inside a picture as pixels
14 // instead of clear text on the page.
15 //
16 // Humans can read the pixels, but the robots can not. For all the robots
17 // know, it is just a boring button or a picture of Tux the Penguin
18 // giving them the finger.
19 //
20 // Some people insert funky codewords like nospam or whatever into their
21 // email addresses. Thats ok too. Image encapsulation, as done here,
22 // protects novice end users who don't nospam their addresses.
23 //
24 // DO THIS
25 // 1. replace the first 3 lines with whatever code fetches an email
26 // address for a user on your system. Make sure you have a way
27 // to index the emails. In my SQL db, I use an integer called userid.
28 //
29 // 2. save as armored_email.php
30 //
31 // 3. In another file, say you want userid 8's email address to appear,
32 // use something like
33 // <IMG SRC=armored_email.php?userid=8> in HTML
34 // or obviously, echo blah... in PHP.
35 //
36 // 4. If you prefer GIF over PNG, change the 2 lines with the word PNG to GIF.
37 //
38 // 5. Tweak font, pad, and colors to taste.
39 //
40 // No support offered. Here are some hints.
41 // * If you can't read PNG, check mime types on your server, or alternatively, check the browser
42 // * my old copy of the linux kde browser cant read png, but it can read gif. This seems evil.
43 // * Don't echo out the email address or add a mailto tag to it, or you'll defeat the purpose.
44 // * Don't just change it to print the string you send to IMG. That's not very safe, either.
45 //
46 // If you can make it better, post a new version.
47 // Happy coding.
48
49 $u = (int) $HTTP_GET_VARS["userid"];
50 $q = mysql_query("SELECT email from users where userid = '".$u."' LIMIT 1;", $db_link);
51 $email = mysql_result($q,0,0);
52
53 $font = 2; // play with this, settings 1-5 are supposedly builtins
54 $pad = 10; // number of pixels to pad around string
55
56 header("Content-type: image/png");
57
58 $len = strlen($email);
59 $charH = ImageFontHeight($font);
60 $charW = ImageFontWidth($font);
61 $strH = $charH;
62 $strW = $len * $charW;
63
64 $imgW = $strW + $pad;
65 $imgH = $strH + $pad;
66
67 $cX = $imgW/2;
68 $cY = $imgH/2;
69
70 $img = ImageCreate($imgW, $imgH);
71
72 $black = ImageColorAllocate($img, 0, 0, 0);
73 $red = ImageColorAllocate($img, 255, 0, 0);
74 $green = ImageColorAllocate($img, 0, 255, 0);
75 $blue = ImageColorAllocate($img, 0, 0, 255);
76 $white = ImageColorAllocate($img, 255, 255, 255);
77
78 ImageFilledRectangle($img, 0, 0, $imgW, $imgH, $green);
79 ImageFilledRectangle($img, 1, 1, $imgW-2, $imgH-2, $white);
80
81 $dX = $cX - ($strW/2) + 1;
82 $dY = $cY - ($strH/2);
83
84 ImageString($img, $font, $dX, $dY, $email, $blue);
85
86 ImagePNG($img);
87 ImageDestroy($img);
88
89 ?>
90
Noch kein Kommentar vorhanden
Dieses Snippet kommentieren
Name *
E-Mail (wird nicht angezeigt) *
Website
Kommentar *
Sicherheitscode *