Advertisement

09.25.2005 at 10:08PM PDT, ID: 21573662
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

How to use HTMLSpecialChars function to check ALL data input fields in PHP?

Asked by NZ7C in PHP Scripting Language

Tags: ,

I have set up the following server side code to validate new user form input. I'm not done with it yet (still need to validate email etc - BTW it is a low traffic site so using server side scripting is not an issue). Before I go further with it I would like toknow how to  have ALL data fields checked for "malicious scripters" by using the HTMLSpecialChars() function. How can I do that with out adding the test individually to all of the fields below - ie how can I have it automatically check any data entry field? Thanks in advance for any help (yes, I'm a struglling beginner :-)

//create short variables
$username = strtoupper(ltrim($_POST['username']));
$firstname = ucfirst (ltrim($_POST['firstname']));
$lastname = ucfirst (ltrim($_POST['lastname']));
$address = ltrim($_POST['address']);
$address2 = ltrim($_POST['address2']);
$city = ltrim($_POST['city']);
$zip = ltrim($_POST['zip']);
$email = strtolower(ltrim($_POST['email']));
$homephone = ltrim($_POST['homephone']);
$workphone = ltrim($_POST['workphone']);
$cellphone = ltrim($_POST['cellphone']);
$password = ltrim($_POST['password']);
$password_ck = ltrim($_POST['password_ck']);

// Test whether the form has been submitted in the first place
if (isset($_POST['Submit']))
  {
   // Test whether your required field is blank
   if (empty($username))
              {
              $ERRusername = TRUE;
              $ERRusernameMsg = "You must enter member name";
              $success = FALSE;
              }              
   if (empty($firstname))
          {
           $ERRfirstname = TRUE;
           $ERRfirstnameMsg = "You must enter first name";
           $success = FALSE;            
          }
    //first name validation              
      if (!eregi("^[a-z]*$",$firstname))      
            {
           $ERRfirstname_alpha = TRUE;
           $ERRfirstname_alphaMsg = "Use only alpha characters.";
           $success = FALSE;            
          }         
   if (empty($lastname))
          {
           $ERRlastname = TRUE;
           $ERRlastnameMsg = "You must enter last name";
           $success = FALSE;            
          }      
      //last name validation              
      if (!eregi("^[a-z]*$",$lastname))      
            {
           $ERRlastname_alpha = TRUE;
           $ERRlastname_alphaMsg = "Use only alpha characters.";
           $success = FALSE;            
          }       
   if (empty($address))
          {
           $ERRaddress = TRUE;
           $ERRaddressMsg = "You must enter an address";
           $success = FALSE;            
          }                  
      if (empty($city))
          {
           $ERRcity = TRUE;
           $ERRcityMsg = "You must enter a city";
           $success = FALSE;            
          }  
      if (empty($zip))
          {
           $ERRzip = TRUE;
           $ERRzipMsg = "You must enter zipcode";
           $success = FALSE;            
          }
//zip code validation                
      if (!ereg("^([0-9]{5})$",$zip))      
               {
           $ERRzip_int = TRUE;
           $ERRzip_intMsg = "Zipcode must contain 5 digits.";
           $success = FALSE;            
          }    
      if (empty($email))
          {
           $ERRemail = TRUE;
           $ERRemailMsg = "You must enter email address";
           $success = FALSE;            
          }
       if (empty($homephone))
          {
           $ERRhomephone = TRUE;
           $ERRhomephoneMsg = "You must enter your home phone";
           $success = FALSE;            
          }           
       if (empty($password))
          {
           $ERRpassword = TRUE;
           $ERRpasswordMsg = "You must enter password";
           $success = FALSE;            
          }  
        if (strlen($password)>12 OR strlen($password)<5)  
              {
           $ERRpassword_len = TRUE;
           $ERRpassword_lenMsg = "Password must be between 5 and 12 characters.  Try again";
           $success = FALSE;            
          }           
       if (empty($password_ck))
          {
           $ERRpassword_ck = TRUE;
           $ERRpassword_ckMsg = "You must re-enter password";
           $success = FALSE;            
          }             
        if (($password)!=($password_ck))
              {
           $ERRpasswords_not_eq = TRUE;
           $ERRpasswords_not_eqMsg = "Passwords entered were not the same.";
           $success = FALSE;            
          }              
             }// End of POST test  
            Start Free Trial
 
 
[+][-]09.26.2005 at 12:46AM PDT, ID: 14956966

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]09.26.2005 at 05:33AM PDT, ID: 14958112

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.26.2005 at 08:22AM PDT, ID: 14959485

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.26.2005 at 08:25AM PDT, ID: 14959523

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.26.2005 at 09:32AM PDT, ID: 14960212

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: htmlspecialchar, php
Sign Up Now!
Solution Provided By: CrYpTiC_MauleR
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.26.2005 at 06:17PM PDT, ID: 14963698

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32