Jump to content

Filtering input and strip_tags?


deerly

Recommended Posts

Hello!

 

I am currently working on a project that is unable to use the handy-dandy filter_var functions because it is using an older version of PHP5.

 

Obviously I still want to filter the input but I don't want to make things slow with a complicated regular expression if I don't have to.

 

This is actually something that's always confused me -- how would you want to go about filtering a block of text that should be able to use punctuation including single and double quotes?

 

Would strip_tags be a good enough filter for a title and block of message text to be safe but still allow the user to freely use punctuation or is this too easily exploited?

 

Thanks for any ideas and insight that I am missing!

Link to comment
Share on other sites

If by filter, you mean strip things you don't like, yes, it doesn't filter. I typically avoid doing such a thing on input that doesn't need to meet specific restrictions. For instance I will be specific with characters in a username, password, etc, but I wouldn't filter a user's post to his blog. Sometimes people like to use things that could qualify as "scary" to an algorithm, for instance mathematic inequalities (5 > 4 > 3) could scare some html stripping algorithms. I don't expect my user to know HTML, so I don't expect them to know how to avoid posting strings that look like html. If they want to post something like... [pre]<a href="candy.jpg"></a>[/pre] Sure, I'll let them do it, but it's also sure as hell going to end up being... [pre]<a href="candy.jpg"></a>[/pre] ...once it is sent to other users.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.