The Artima Developer Community
Sponsored Link

PHP Buzz Forum
PHP Security - Ideas for Building a HttpRequest Class

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Pure-PHP

Posts: 20
Nickname: purephp
Registered: Mar, 2005

Pure-PHP is kind of Blog about PHP, and unconventional methodes to boost PHP-apps
PHP Security - Ideas for Building a HttpRequest Class Posted: Mar 19, 2005 3:16 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Pure-PHP.
Original Post: PHP Security - Ideas for Building a HttpRequest Class
Feed Title: Pure PHP - PHP unconventional
Feed URL: http://www.iran-fun.com/
Feed Description: Unconventional methodes to boost php apps
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Pure-PHP
Latest Posts From Pure PHP - PHP unconventional

Advertisement

First of all PHP is secure, and I am not the only and first one to write it. Many PHP apps has seem to be insecure in the recent time. It has nothing to do with php at all. First of all, no other programming language is disposed to the "evils" (sorry ;-)) outside, scond while php is so easy to learn, some of the developer had no programming language experience before writing apps in PHP, therefor the security problems of the poular phpbb was a good lesson fo the PHP community.

I have the Idea of writing a HttpRequest class, which every devolper cann use. Here is the basics, and I would be lucky to get your ideas.

<?php

class HttpRequest{
    var
$params = array();
    function
HttpRrquest(){
        
$this->params = &$_REQUEST;
    }    
    function
getInt($k){
        return
intval($this->params[$k]);
    }
    function
getString($k){
        return
strval($this->params[$k]);
    }
    function
getAlNum(){
        if(
ctype_alnum($this->params[$k])){
            return
$this->params[$k];
        }else{
            return
null;
        }
    }
    function
getSqlEscaped(){
        return
addslashes($this->params[$k]);
    }
    
//more to be done
    
function getXSSCleaned($allowedTags = ""){
        return
addslashes($this->params[$k]);
    }
    function
getEmail(){
        
$email = strtolower($this->params[$k]);
        if(!
preg_match("/^([_[:alnum:]-]+)(\.[_[:alnum:]-]+)*@([[:alnum:]])([[:alnum:]\.-]+)([[:alnum:]])\.([[:alpha:]]{2,4})$/",$email)){
            return
null;
        }else{
            return
$email;
        }
    }
    function
getFloat($k){
        return
floatval($this->params[$k]);
    }
    function
getDouble($k){
        return
doubleval($this->params[$k]);
    }
}
class
httpCookie extends HttpRequest{
    function
httpCookie(){
        
$this->params = &$_COOKIE;
    }
}
class
httpGET extends HttpRequest{
    function
httpGET(){
        
$this->params = &$_GET;
    }
}
class
httpPOST extends HttpRequest{
    function
httpPOST(){
        
$this->params = &$_POST;
    }
}

?>

usage:

<?php

$post
= new httpPOST();
if(
$post->getAlNum("id") == null{
  echo
"invalid id";
}
if(
$post->getInt("id"){
  
$query = "SELECT * FROM table WHERE id =".$id;
}
$query = "INSERT INT Table (msg) VALUES ('".$post->getSqlEscaped("msg")."')";
?>

Write your ideas for (other) metodes

Read: PHP Security - Ideas for Building a HttpRequest Class

Topic: N-TEN NTC and Penguin Day Chicago Previous Topic   Next Topic Topic: Database Portability (Part 3)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use