|
-
Mar 13th, 2004, 05:20 AM
#1
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;
-
Mar 13th, 2004, 01:35 PM
#2
Stuck in the 80s
What kind of application do you have where you'd need to do this? Just curious.
-
Mar 13th, 2004, 02:03 PM
#3
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.
-
Mar 15th, 2004, 08:08 AM
#4
Frenzied Member
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?
-
Mar 15th, 2004, 12:04 PM
#5
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
-
Mar 15th, 2004, 12:14 PM
#6
Frenzied Member
-
Mar 25th, 2004, 03:52 PM
#7
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|