Results 1 to 12 of 12

Thread: Comments. Restrict userinput.

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Comments. Restrict userinput.

    I have for a long time, restricted a lot of input in my comments on my web page. Just because I have never had time to get on top of what can be dangerous and what is not dangerous to allow to be added.


    but I want to change this a bit. What should I be carefull about. Is there any HTML tags I should now allow? What about JS, how can I prevent this. Just addslashes or what?


    Thanks.
    - ØØ -

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Comments. Restrict userinput.

    I found the best way is to just stop all HTML tags, and if you want the user to have some formatting then implement some kinda of BB tags. Its just means that they cant have javascript, or CSS, which will mess up the display of your site. To convert html to friendly version look at htmlentities().

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Comments. Restrict userinput.

    But if I want to implement vBulleting tags. IF I use that function you showed me. Wouldn't the vBulletin tags get converted then?

    Wouldn't it be better to use strip_tags()


    ??

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Comments. Restrict userinput.

    The BB tags would get converted to HTML but any HTML that the user tried to display would either be convert to &gt; &lt; etc. But yes if you used strip_tags() it would remove the HTML before you parsed it with the BB code. It just depends if you want people to be able to post HTML so that it appears like on here

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Comments. Restrict userinput.

    I use htmlentities() and BB tags like John suggested. htmlentities() does not affect BB tags in any way.

    If you decide to use regex's for it feel free to rip them from my parser (a bit messy, but works fairly well):
    http://dev.penagate.spiralmindsinc.c...er/bbcode.phps

    Ignore the [img] tags though.

  6. #6
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Re: Comments. Restrict userinput.

    Quote Originally Posted by penagate
    I use htmlentities() and BB tags like John suggested. htmlentities() does not affect BB tags in any way.

    If you decide to use regex's for it feel free to rip them from my parser (a bit messy, but works fairly well):
    http://dev.penagate.spiralmindsinc.c...er/bbcode.phps

    Ignore the [img] tags though.
    Do you have a bookmark or resource that teaches string literals? The PHP manual has rather limited info and Google shows string literals for languages I've never even heard of... unless it's all the same?

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Comments. Restrict userinput.

    I am not sure what you mean. A string literal is just a string that is hardcoded.

    In PHP there are two types of string literal, those with single quotes and those with double quotes. Single-quoted literals are not parsed. Double quoted literals are parsed for escape sequences (\n, \0 etc.) and variables.

    PHP Code:
    $something 5;
    echo 
    '$something';  // outputs $something
    echo "$something";  // outputs 5 
    Is that what you were after?

  8. #8
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Re: Comments. Restrict userinput.

    Oh, um. I think I called it the wrong thing then? I mean this stuff in your example code:

    ([a-z0-9\+\-=\._\/\*\(\),@\'$:;&\!\?\~\#]*)

    I'm reading it and I've got to the part... a-z lower case, 0-9, and then I'm lost. lol

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Comments. Restrict userinput.

    Those are called regular expressions. You can learn them here:
    regularexpressions.info

    PHP can use both ereg and preg expressions. preg is the more common type. I don't know anything about ereg's.

  10. #10
    New Member
    Join Date
    Apr 2006
    Posts
    14

    Re: Comments. Restrict userinput.

    Thanks! That's exactly what I'm looking for. ^_^

  11. #11

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Comments. Restrict userinput.

    Quote Originally Posted by john tindell
    The BB tags would get converted to HTML but any HTML that the user tried to display would either be convert to &gt; &lt; etc. But yes if you used strip_tags() it would remove the HTML before you parsed it with the BB code. It just depends if you want people to be able to post HTML so that it appears like on here
    Ahh..I was thinking that also the [ and ] would change into &#91; and &#93; too.. My head was probably spinning that day. Well, then I guess both can be used, with different results. Thanks.



    Still I would be keen to hear about SQL injection and any other threats I might not know about..


    - ØØ -

  12. #12
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Comments. Restrict userinput.

    check out http://www.devarticles.com/c/a/MySQL...-Are-You-Safe/

    [EDIT]
    the code example on that link are in ASP but the principles they talk about are the same

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