How can PHP be used to encrypt email addresses on a website for spam protection?
To encrypt email addresses on a website for spam protection, you can use PHP to encode the email address in a way that is not easily recognizable by spam bots. One common method is to use a combination of string manipulation functions and base64 encoding to obfuscate the email address.
<?php
function encrypt_email($email) {
$encrypted_email = '';
for ($i = 0; $i < strlen($email); $i++) {
$encrypted_email .= "&#" . ord($email[$i]) . ";";
}
return $encrypted_email;
}
$email = "example@example.com";
$encrypted_email = encrypt_email($email);
echo "<a href='mailto:" . $encrypted_email . "'>" . $encrypted_email . "</a>";
?>
Keywords
Related Questions
- What is the potential issue with using the body onLoad="location.reload();" function in PHP to automatically reload a page?
- What are the potential pitfalls of setting cookies in PHP and how can they be avoided?
- How can inconsistencies in the length of private and public keys affect the functionality of reCaptcha in PHP scripts?