PHP
  Home arrow PHP arrow Page 5 - Reconsidering PHP variables
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Reconsidering PHP variables
By: Iulian Turnea
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 45
    2005-01-10


    Table of Contents:
  • Reconsidering PHP variables
  • Counting your cookies?
  • Checking variable types
  • A Method to your madness
  • Its the size that matters
  • Pssst... Whats the password?
  • And in Conclusion...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Reconsidering PHP variables - Its the size that matters
    ( Page 5 of 7 )

    Lets come back to the variables themselves.  In addition to checking the type of variable, we can also check the size or length as well.  One of the largest exploited issues among all types of software are 'buffer overflow' problems.  This is when more data is passed than the variables expect, and the data starts filling in other memory and variable locations.  If you check the length and size of your data, then you can harden yourself to this kind of exploit.  For example:

    <a href = index.php?action=1> Page1 </a>

    Use this code to check if the variable content has more than one character.

    $length = strlen($_GET['action'] );
    if($length>1){
    header(" Location:./error.php ");
    exit;
    }

    or

    $length = strlen($_GET['action'] );
    if($length!=1){
    header(" Location:./error.php ");
    exit;
    }

    In the same way you can check text. You can allow as many characters as you wish, and reject the rest.  For example:

    $length = strlen($_GET['text1'] );
    if($length>3000){
    header(" You can send up to 3000 characters ");
    exit;
    }

    Notice that there are 3000 characters allowed including white spaces.



     
     
    >>> More PHP Articles          >>> More By Iulian Turnea
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT