WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : Forms protected from XSS attacks (FOPAXSS)
Categories : PHP, PHP Classes, Form Processing, Security
ROBERTO ALEMAN
Date : Dec 18th 2009
Grade : 3 of 5 (graded 3 times)
Viewed : 6614
File : No file for this code example.
Images : No Images for this code example.
Search : More code by ROBERTO ALEMAN
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

Forms protected from XSS attacks (FOPAXSS)

index.php
<?php
/* Forms protected from XSS attacks (FOPAXSS) by Roberto Aleman, Enjoy it, test it and improve it! */

//calls to scripts
require_once("fopaxss.php");
$val = new fopaxss();

//captch submit
if(isset($_POST['submit']))
    {
       
$val-> val_txt_field_or_numbers($_POST['txt']);
       
$val-> val_date($_POST['date']);
       
$val-> val_hexadecimal($_POST['hexadecimal']);
       
$val-> val_email($_POST['email']);
       
$val-> val_password($_POST['password']);
    }
//show results
$val-> enginecontactform($_POST['txt'],$_POST['date'],$_POST['hexadecimal'],$_POST['email'],$_POST['password']);  //add type fields in orden
?>




fopaxss.php
<?php
/* Forms protected from XSS attacks (FOPAXSS) by Roberto Aleman Enjoy it, test it and improve it! */
class fopaxss
{
   
    function
val_txt_field_or_numbers($txt)
        {
       
$validation = htmlentities($txt);//clear of bad input
       
if($validation != NULL)
        {
            if (!
preg_match("(\S[^\t\n\r][A-Za-z0-9])",$validation))  //Letters & numbers uppercase or undercase
                   
{
                        echo
"Text Incorrect or vulnerable!, sorry a valid input is Letters & numbers uppercase or undercase<br/><br/>";
                        }
                    else
                    {
                        echo
"input Text correct and no vulnerable!<br/>your input:".$validation."<br/><br/>";
                       
                    }
        }
        else
        {
            echo
"your input is NULL<br/>";
                        }
        return;
        }
   
    function
val_date($date)
        {
           
$validation = htmlentities($date);//clear of bad input
           
if($validation != NULL)
        {
            if (!
preg_match("(\d{1,2}\/\d{1,2}\/\d{4})",$validation))  //valid date (e.g. 17/12/2009)
                   
{
                                echo
"input Date Incorrect or vulnerable! sorry valid date (e.g. 17/12/2009)<br/>";
                                }
                    else
                    {
                        echo
"input Date correct and no vulnerable!<br/>your input:".$validation."<br/><br/>";
                        }
        }
        else
        {
            echo
"your input is NULL<br/>";
                        }
                return;
        }

    function
val_hexadecimal($hexadecimal)
        {
           
$validation = htmlentities($hexadecimal); //clear of bad input
           
if($validation != NULL)
        {
            if (!
preg_match("(#?([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?)",$validation))  // Valid hexadecimal colour code
                   
{
                                echo
"input hexadecimal Incorrect or vulnerable! remenber hexadecimal good value is #000000 (black) by example<br/>";
                                }
                    else
                    {
                        echo
"input hexadecimal correct and no vulnerable!<br/>your input:".$validation."<br/><br/>";
                        }
        }
        else
        {
            echo
"your input is NULL<br/>";
                        }
                return;
        }

    function
val_email($email)
        {
           
$validation = htmlentities($email);//clear of bad input
           
if($validation != NULL)
        {
            if (!
preg_match("(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})",$validation))  //valid email structure
                   
{
                                echo
"input email Incorrect or vulnerable!<br/>";
                                }
                    else
                    {
                        echo
"input email correct and no vulnerable!<br/>your input:".$validation."<br/><br/>";
                        }
        }
        else
        {
            echo
"your input is NULL<br/>";
                        }
                return;
        }

    function
val_password($password)
        {
           
$validation = htmlentities($password);//clear of bad input
           
if($validation != NULL)
        {
            if (!
preg_match("((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15})",$validation))  //8 to 15 character string with at least one,upper case letter, one lower case letter,and one digit (useful for passwords).
                   
{
                                echo
"input password structure Incorrect or vulnerable!, this is good structure 8 to 15 character string with at least one,upper case letter, one lower case letter,and one digit<br/>";
                                }
                    else
                    {
                        echo
"input passwoord correct and no vulnerable!<br/>your input:".$validation."<br/><br/>";
                        }
        }
        else
        {
            echo
"your input is NULL<br/>";
                        }
                return;
        }
/*  here more validation structures see the partner */       

   
function enginecontactform()
        {
       
// this a form of example but can expand easily
           
echo "<div class='contact'>
                        <a name='contact' id='contact'></a>
                            <form action='index.php' method='post' >
                            <p>Your text input:<br/><input name='txt' type='text' size='20' maxlength='20' /></p>
                            <p>Your date input:<br/><input name='date' type='text' size='20' maxlength='20' /></p>
                            <p>Your hexadecimal input:<br/><input name='hexadecimal' type='text' size='20' maxlength='20' /></p>
                            <p>Your email input:<br/><input name='email' type='text' size='20' maxlength='20' /></p>
                            <p>Your password input:<br/><input name='password' type='password' size='20' maxlength='20' /></p>
                            <input name='submit' type='submit' />
                            </form>
                  </div>"
/// see action tag , and change for your custom url
       
return;
        }
}
?>



A damaged image generator (class) for validating text. CAPTCHA - Completely Automated Public Turing test to tell Computers and Humans Apart
Categories : PHP, PHP Classes, Security, GD image library, Security
cPanel Email Accounts Creator
Categories : PHP, PHP Classes, Email, Form Processing, Web Services
FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps
Use of bitmasks to represent permissions
Categories : PHP, Authentication, Bitwise Operators, Security, PHP Classes
Creates a CAPTCHA image in PHP, which displays 5 numbers stored in a session.
Categories : PHP, GD image library, Form Processing, Security
Scan Apache access log files and report possible worms attack
Categories : PHP, PHP Classes, Security, Apache, Log Files
Generating and Matching Secure and Strong Password Hash
Categories : PHP, PHP Classes, Cryptography, Security
Antispoof - a class to help prevent people hi-jacking and misusing parts of a website
Categories : PHP, PHP Classes, Security
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
Db_lib - practical example usage of database abstraction and form validation.
Categories : PHP, Form Processing, PHP Classes, Data Validation, Beginner Guides
Function to generate readable/remeberable random password
Categories : PHP, Security, Security
Scramble Eggs - php class to scramble/encode
Categories : PHP, PHP Classes, Security, Encryption
Form Elements Class
Categories : PHP, PHP Classes, Form Processing
addslashes automatically to $_POST variables
Categories : PHP, Form Processing, Security
send_mail function to defeat Header Injection Hacking/Spamming
Categories : PHP, Email, Form Processing, Security