Miscellaneous Code

  Home arrow Miscellaneous Code arrow Request macros
MISCELLANEOUS CODE

Request macros
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-02-16

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    Tired of typing if(isset($_POST['submit'] && $_POST['submit'] == 'UPDATE'))? Here is a simple class that will abstract some of that.

    By : MadAlbert

    <?
    class req {
    function get($var,$sub=False){
    return (isset($_GET[$var]))? $_GET[$var]:$sub;
    }
    function post($var,$sub=False){
    return (isset($_POST[$var]))? $_POST[$var]:$sub;
    }
    function request($var,$sub=False){
    return (isset($_REQUEST[$var]))? $_REQUEST[$var]:$sub;
    }
    function server($var,$sub=False){
    return (isset($_SERVER[$var]))? $_SERVER[$var]:$sub;
    }
    function session($var,$sub=False){
    return (isset($_SESSION[$var]))? $_SESSION[$var]:$sub;
    }
    function getEQ($var,$eq){
    return (req::get($var) == $eq)?True:False;
    }
    function postEQ($var,$eq){
    return (req::post($var) == $eq)?True:False;
    }
    function requestEQ($var,$eq){
    return (req::request($var) == $eq)?True:False;
    }
    function serverEQ($var,$eq){
    return (req::server($var) == $eq)?True:False;
    }
    function sessionEQ($var,$eq){
    return (req::session($var) == $eq)?True:False;
    }
    }


    /*USAGE

    There is no need to instanciate the class has it has no internal values to track so usage is like this:

    if(req::postEQ('submit','UPDATE')){
    do something;
    }
    if you need to see if a variable is set then use

    if(req::post('submit'){
    do something;
    }
    If you need to use the posted variable but have a replacement if it is not set then do:

    $name = req::post('name','no name given');
    or
    $id = req::post('userid',0);

    There are macros for _POST _GET _REQUEST _SERVER and _SESSION
    Doing it this way you just need to include the class, I use auto prepend to do it automatically on every page.
    */
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap