Results 1 to 7 of 7

Thread: securing POST and GET using expressions

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    securing POST and GET using expressions

    Anyone have a good preg_replace expression or even a different method of securing any variables I might want to? I'm looking to include A-Z, a-z, 0-9, and all of the SHIFT+KEY keys, and not allow any others. So, it's basically only the 'easily typable' keys.

    Any help would be appreciated.. I could just make a safe array and do that, but I'm looking for a more efficient way that's only a line or two of code.

    I've used this string in Perl before, but I have no idea of how to convert it over to PHP.. I tried a bit, but couldn't get it..

    Code:
    $str =~ s/[^A-Za-z0-9_]//gs;
    Like Archer? Check out some Sterling Archer quotes.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    What kind of application do you have where you'd need to do this? Just curious.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    storing usernames and don't want to allow the alternate number pad ascii characters, also just want to remove evil characters from POST and GET requests.
    Like Archer? Check out some Sterling Archer quotes.

  4. #4
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Sorry to slightly derail this thread, but I had a similar question. Would checking for ampersands in the POST/GET array be enough in terms of a security check for user input? I mean, if a user were to try and sneak an extra variable in there, and you checked for ampersands, wouldn't that be enough to catch it?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    this is what I've used for a while to clean POST and GET.. i've modified it a bit and removed some code that i'm using to clear values for member names though.

    to avoid losing some of the formatting, here's the source:

    http://david.gamersepitome.net/files...file=clean.php

    just include it into a config file or call the config file within it and any call to a GET or POST variable will be auto-cleaned
    Like Archer? Check out some Sterling Archer quotes.

  6. #6
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Excellent. Thanks.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by kows
    storing usernames and don't want to allow the alternate number pad ascii characters, also just want to remove evil characters from POST and GET requests.
    if (preg_match("/[0-9a-zA-Z]/, $post)){

    if it doesn't have numbers or letters than it retuns flase. no ned to worry about the numpad.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width