WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Protect your email addresses online
Categories : PHP, Email Click here to Update Your Picture
Sarah King
Date : Jul 19th 2004
Grade : 3 of 5 (graded 2 times)
Viewed : 5120
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Sarah King
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 


contributed by http://sarahk.pcpropertymanager.com/obfuscate.php
see working example!
at the moment mail harvesters/bots don't read this code,
therefore your email addresses are protected if you put them
on your page like this.
browsers still read them

[code]
<?php
function getEmail($name)
{
   
$name .= '@mysite.com';
   
$email = getOrdString('mailto:'.$name);
   
$label = getOrdString($name);
   return
"<a href='{$email}'>{$label}</a>";
}

function
getOrdString($string)
{
   for(
$i=0;$i<strlen($string);$i++) $output .= '&#'.ord($string[$i]).';';
  return
$output;
}
//function getOrdString($string)
?>



email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
PHP based Contact email form with multiple recipients, text file based, supports departments.
Categories : PHP, Email, Beginner Guides, Filesystem
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
A web-based php3 IMAP email client supporting address books, attachements (downloading and sending), LDAP searching, and much much more.
Categories : Email, PHP, LDAP
Encoding data using PGP via PHP's proc_* functions
Categories : Cryptography, Security, Email, PHP, PGP
email validator check checker email e-mail email address
Categories : PHP, Email, Regexps
Mail-lib provides a simple interface to the sendmail program. Note: you must actually have sendmail on your machine (sorry windows NT users).
Categories : Algorithms, Email, PHP
PHPRecommend v1.0 - "Recommend this page to a friend" script written in PHP. Easy to install
Categories : PHP, URLs, Complete Programs, Email, Site Planning
validateEmail 2.0 - upgraded version of the old validateEmail function used to validate email addresses via SMTP and regex.
Categories : Email, Regexps, PHP
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
making links from text
Categories : PHP, Regexps, Email
HTTP Basic Authentication via POP3.
Categories : Authentication, HTTP, Email, PHP
A PHP based webmail at : http://www.horde.org/imp
Categories : Email, IMAP, PHP, Complete Programs
Protect your mailto: email addresses from bots - pure PHP
Categories : PHP, Email, Security
Protect your email links from being spidered by spam email robots!
Categories : PHP, Security, Mail, Email
 matthew waygood wrote : 1150
This is absolutely rubbish.
PHP is run server side and produces results that can be seen by browsers and bots.

In order to protect you email from bots you must use javascript which is run client side.

what you need to protect your email address is:-
&lt;script language="JavaScript"&gt;
&lt;!-- Begin
user = "matthew";
site = "somewhere&#46;co&#46;uk";

document.write(`&lt;a href=\"mailto:` + user + `&#64;` + site + `\"&gt;`);
document.write(`&gt;&gt;Contact me&lt;&lt;&lt;/a&gt;`);
// End --&gt;
&lt;/script&gt;

You could write a php function to take the parameters and output the above. which I will do for you as my own example
 
 Sarah King wrote : 1151
I disagree. 

This code hides the vital mailto and @ symbols and at the moment the harvesters appear to be too lazy to code their bots to read & interpret absolutely everything in an &lt;a&gt; link.

The more any of this is publicised, obviously, the more likely the spammers are to find a way around the technique. But that goes for javascript too. 

Thanks for your comments, though, Matthew.
 
 Adam Ewing wrote : 1154
As stated by Matthew PHP runs server side so I prefer not to send the email address to the browser at all.  Instead provide a html form for the user to fill in and then use the php mail() function (or the available formmail script) to send the mail behind the scenes.  I have the form and receive script as code blocks I just add to a project and away you go.

As the email is coded into the php script even if it is called from a browser it will not display.  You can even go the next step and have this include another php script that is NOT in the public area of the webserver that has a php variable with the email address.  You could even store the address in a database and then you can talk about encrypting it as well.

I know that this goes a lot further than a simple mailto link but I feel the form is in some ways a more elegent way of doing it.  

 
 Sarah King wrote : 1172
Having stated that this is rubbish, Matthew seems to have changed his mind and is recommending that you don`t use Javascript but a similar server side process: http://www.weberdev.com/get_example.php3?count=3951
 
 matthew waygood wrote : 1226
Yup I did a u turn on this. The suggestion to encode the mailto: is a good one.
To make it more difficult for bot to find "mailto:" or the coded equivalent, the example I suggested uses randomly chosen hex/dec codes for each character so finding the coded equivalent is more difficult. I have amended this to also allow the normal character to be used (which is potentially bad - but added a lesser probability of it choosing this)

ie
converting abc to &#1;&#2;&#3; allows bot to search for &lt;a href="&#1;&#2;&#3;....."
converting abc to a&#2;&#x07; makes it more difficult to do a pattern match as there are greater combinations).
(this is an example and not the actual codes)
 
 matthew waygood wrote :1227
Ah! those squares where supposed to be &amp;#01; and &amp;#x07;