Saturday, 15 February 2014

Top Anti-Spam Techniques For PHP Websites

PHP, Captcha, PHP security, anti-spam techniques, best security techniques, websites spam, stop spam, how to stop spam, best PHP anti-spamming techniques, PHP tips, PHP tricksTired of constant spamming on your website? Here are the steps that you can take. 

When running a website, it is very important to protect yourself from spammers. If you're working on a PHP website, there are many ways to do this. Here are the top seven methods to stop spamming on your website.



1. CAPTCHA: You probably already know what CAPTCHA is. Websites often ask you to enter text in order to identify yourself, this is done through CAPTCHA. You need to add the CAPTCHA image and a text input to whatever you’re trying to protect on your website.

In order to implement CAPTCHA, you need to first install the Text_CAPTCHA class. In addition, you need the Text_Password and Image_Text classes to be installed too.

Use the following commands in order to install Pear’s Text_CAPTCHA class.

# pear install -f Text_CAPTCHA
# pear install -f Image_Text


Then you need the captcha.php file, which is the script that will generate the CAPTCHA image. Further, you need the TrueType font to be kept in the same directory as captcha.php. Why? Because this is the fond that is used in order to write a secret phrase.

On Windows these fonts are usually present in: C:\Windows\Fonts directory.

This is how the captcha class looks,


require_once('Text/CAPTCHA.php');



session_start();

$phrase = isset($_SESSION['captcha']) ? $_SESSION['captcha'] : 'Error';



$options = array('font_size' => 24, 'font_file' => 'georgia.ttf');



$cap = Text_CAPTCHA::factory('Image');

$cap->init(120, 60, $phrase, $options);



header('Content-type: image/png');

echo $cap->getCAPTCHAAsPNG();

?>


The code given above doesn’t perform any error checks. In case you want that, you will have to add it yourself. In addition, it will use the text “Error” if no phrase is found. In such a case, the user will never be able to cross the CAPTCHA message.

The PHP code for the form processor and the form are as follows. This is a very simple version and real form processing will have much more to it.

//
//session_start();

//

//if(isset($_POST['process'])){

// if(!isset($_SESSION['captcha']))

// die('Form accessed incorrectly');

//

// if(isset($_POST['captcha']) && $_POST['captcha'] == $_SESSION['captcha']){

// die('CAPTCHA text matched! Phrase was '.$_SESSION['captcha']);

//}else{

// die('CAPTCHA text did not match. Phrase was '.$_SESSION['captcha'].

// ', you entered '.$_POST['captcha']);


//}else{

// generate a new CAPTCHA phrase

// $_SESSION['captcha'] = substr(md5(uniqid(null)), 0, 4);
//}
//?>
//
//
// CAPTCHA Demo
//

//

//


//


// Enter phrase:

// input type="submit" name="process" value="Submit" />
// /form>
//
//


This code is using MD5 and uniqid() to generate a random string of text for our phrase. You can make your own changes to it.

2. Moderation or Manual Approval: This is again pretty self explanatory. You (the admin) moderates every new user that joins or comment that is made on your website. Before you validation, the user can’t pass or comments can’t show up on the website.

All you have to do is add a new item to your SQL table, which shows whether a new item has been approved by you or not. It requires a lot more work from the admin.

3. Text Filters: In this, you can check for words that are recognised as spam and block a post with such words. The functionality for this is already included in WordPress if you’re using it.

4. Email Validation: You can also ask the user to enter their email address while submitting a form. This sends an email to the user with a link that has to be clicked for authorisation. It ensures that the user is using a valid email address.

5. Rewriting: This method is used for protecting your email address from spammers. In this you spell out your email address. For example, efy (at) efytimes (dot) com. So, someone sending you a mail can’t simply copy and paste the address, they will have to write it down themselves. Someone doing so will usually be a real user, who is not sending you spam.

You can use this code,

{assign var='email' value='antispam@example.com'}
{$email|escape:'mail'}


This will give an output: antispam [AT] example [DOT] com.

6. Image: In this you display your email id as a picture instead of plain text. Email harvesters find this to be the toughest to deal with. If you put this in the same font and size as the rest of the website you many won’t even recognise that it is an image unless they try to copy it.

This can either be done using Photoshop to create the image, or you can use ImageTTF() to draw out TrueType fonts and then use the ImageTTFBBox() function.

7. Forms: This is often a technique that users tend to avoid. In this you provide a form that links directly to your email address. A real user can fill up the form to contact you. This though is far from foolproof as spammers can use the form to send you spam. You can create this by using the mail() function.

Author : Shivam Kotwalia, CodeKill

No comments:

Post a Comment

Blog Archive

Labels

Tutorial (129) Tech News (83) E-Books (55) Pdf (47) Hacking (46) Linux (32) Android (23) Programming (22) Tools (22) Video (21) Ethical Hacking (16) Electronics (12) Google (10) Hacked (9) Python (9) Facebook (8) Java (8) Software (8) PHP (7) Android App (6) C (6) Free Online Coureses (6) OpenSource (6) Ubuntu (6) Unix (6) Windows (6) C++ (5) Game Programming (5) Java Programming (5) Kali Linux (5) CodeKill (4) Cryptography (4) Firefox (4) JavaScript (4) Linux System Administrator (4) Mac (4) Penetration testing (4) Python Programming (4) Security (4) Top Distros (4) WhatsApp (4) CSS (3) Circuit (3) Cloud Computing (3) Game Devlopment (3) Hacking Tools (3) Malware (3) MicroController (3) Microsoft (3) Networking Tool (3) Perl (3) Source Code (3) WebSite (3) Windows 8.1 (3) C Programming (2) C Series (2) C# (2) CheetSheet (2) Computer (2) Computer Networking (2) Data Storage (2) Dual Boot (2) Eclipse (2) Edward Snowden (2) Exploit (2) Facts (2) Games On Linux (2) Google Chrome (2) HTML5 (2) Hacking Challenges (2) IDE's (2) Information Security (2) Lenovo (2) Linux Kernel (2) Malicious (2) Mobile (2) Motorola (2) Mozilla (2) MySQL (2) NoSQL (2) Raspberry Pi (2) Ruby (2) Security Tools (2) Syrian Electronic Army (2) Tricks and Tips (2) Valentine Day (2) Web Design (2) iOS (2) iPhone (2) jQwery (2) *nix (1) 2014 (1) 3D Modeling (1) Algorithm (1) Android Hacking (1) Android Pattern Lock Screen.. (1) Anonymous Mail (1) Anti-Spam (1) Apps (1) Arduino (1) Artificial Intelligance (1) Audio Software (1) BSD (1) BeAWARE (1) Bitcoin (1) Black Hat Hackers (1) BlackBerry (1) Buffer Overflow (1) C++ vs Java (1) CISO (1) Circuit Analysis (1) Circuit Design (1) Circuit Programming (1) Circuit Simulators (1) Codes (1) Crptology (1) Cryptanalysis (1) DDOS (1) Devlopers (1) Drupal (1) DuckDuckGo Search Engine (1) E-Card (1) E-Mails (1) Embedded System (1) Encryption Tools (1) Error (1) FTP (1) Famous Passwords (1) FileZilla (1) Flipkart (1) Forbes (1) Forgot Password (1) GCHQ (1) Genders (1) Gmail (1) Google Tricks and Trips (1) HTML (1) Hacking Distro (1) Hard Disk (1) Hash Encryption (1) Illegal (1) Internet (1) LAMP (1) Language Theory (1) LibreOffice (1) Linus Trovalds (1) Logic Gates (1) MATLAB (1) MOSFET (1) Mail (1) Mark Zuckerberg (1) Mathematical (1) MicroProcessor (1) Mind Mapping Tools (1) Myntra (1) NoSQL Database (1) Nobal Prize (1) Nokia (1) Object Oriented Programming (1) Office (1) Oldboot (1) Online (1) Paranoid Android (1) Passwords (1) Passwords Cracking Tools (1) PayPal (1) Perl Programming (1) Plugins (1) Prolog Programming (1) Python Basics (1) Remote (1) SEA (1) SQL Injection (1) Sans (1) Screencasts (1) Screenloggers (1) Server Load (1) Servers (1) Shell (1) Software Design (1) Software Developer (1) Software Testing (1) Sony (1) Spider.io (1) Statistical (1) Steve Jobs (1) TCP/IP (1) Timeline (1) Tor (1) Trojan (1) Ubuntu Phones (1) VAIO (1) Virus (1) Web Designers (1) Wi-Fi Hacking (1) Windows Tools (1) Windows XP (1) WordPress (1) XML (1) Yahoo (1) YouTube (1) cpp (1) eBay (1) iBanking (1)