This is a discussion on "easiest filter" within the PHP Forum section. This forum, and the thread "easiest filter are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
easiest filter
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
||||
|
||||
|
what is the quickest way to filter user input so that malicious code can not be saved?
thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
|
|
#2
|
||||
|
||||
|
Re: easiest filter
also how do you check if a certain character or phrase is in a variable.
e.g. check if the following has "123" in it.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#3
|
|||
|
|||
|
Re: easiest filter
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#4
|
||||
|
||||
|
Re: easiest filter
Thanks for the link
anything on automatic filter? and how do I get this to work
and I don't want to do it manually ($list[0], $list[1])
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#5
|
|||
|
|||
|
Re: easiest filter
Alex
If you want to check if <, > or 'lol' are in a string you could try: $check = ereg("(<|>|lol)", $string, $res); The first param is a regular expression: these are difficult. Here I am trying to search for < > or lol - the | indicates or. Basically you have to build a regular expression for your match. if you just wanted to match 'lol' it would be "lol" . To match all digits it would be "\d". It gets complicated. You can still check for $check is true to see if you had a match - but using the third param puts the actual match into an array. (If you need to use this you could perhaps look up ereg() on php.net to see some examples). i haven't been able to test my solution but let me know if you still have a problem re. filters: in fact you need to use regular expressions and substitution preg_replace() does the trick. Works much as ereg() but with replacing. Justin |
|
#6
|
||||
|
||||
|
Re: easiest filter
okay.
for filtering user input, would htmlentities be okay?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#7
|
|||
|
|||
|
Re: easiest filter
no. I think that is something to do with encoding certain characters such as < in the html entity ref form. not to do with filtering
what exactly do you want to do -can you explain a bit more? or give me an example? I was assuming you meant filtering input from a form to check it has no malicious code it? if so then something like this does it: $safedata = preg_replace("eval","",$userInput); This would replace any word 'eval' in $userInput with an empty string i.e get rid of it. The tricky bit is what to use as the expression to match. What characters do you want to test for? Justin |
|
#8
|
||||
|
||||
|
Re: easiest filter
say it's a registration form.
i'd only want numbers, letters, hyphens, underscores, full-stops and @s how would i do that
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#9
|
|||
|
|||
|
Re: easiest filter
ok
I can look at this again later if you like Justin |
|
#10
|
||||
|
||||
|
Re: easiest filter
okay so how would i go about getting a variable 'username' using post and inserting it into mysql via that filter
I don't know how to piece it together. thanks so far though
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#11
|
|||
|
|||
|
Re: easiest filter
ok. Alex. I'll look at this tonight
Justin |
|
#12
|
|||
|
|||
|
Re: easiest filter
(if no one else tells you by then)
|
|
#13
|
||||
|
||||
|
Re: easiest filter
Okay
thanks for the help so far *reps you*
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
|
#14
|
|||
|
|||
|
Re: easiest filter
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#15
|
|||
|
|||
|
Re: easiest filter
Hi Alex
This is it:
Codepunk was wrong. If the regular expression did not match it doesn't mean that it contained invalid data it means it just didn't make any matches. If it contained some valid characters and some invalid you will still get matches . The basic idea is we are matching the characters you want and keeping them. This is different from checking for characters we don't want. The two hard bits are the regular expression itself:
The regular expression uses a character class [] to test for a-z lower and upper case, 0-9 and the other chars you wanted (note the escape \ before them). I''ll leave you to figure out the multi-dimensional array ok. that's it on this one i think. Good luck Justin Last edited by Kropotkin; Aug 23rd, 2007 at 21:47. |
|
#16
|
|||
|
|||
|
Re: easiest filter
ok, what he said.
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
#17
|
||||
|
||||
|
Re: easiest filter
thanks guys I'll look over that tonight
-reps both-
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Tags |
| filter, filtering |
| Thread Tools | |
|
|
|
|