Results 1 to 9 of 9

Thread: JS, ASP: Code blocker

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    JS, ASP: Code blocker

    What I'm creating is a forum.

    What is the best way to block problems in a user message.
    For example I do not want them inputing their own HTML:
    Code:
    <B><I>
    Also, no Javascript:
    Code:
    <SCRIPT> 
     open infinate windows
    </SCRIPT>
    ect.
    Do you see what I mean?

    I hird a while ago of a command called [scriptblock]
    but that is not poping up any search results on this forum or google.

    I don't want my forum running any JS code, or even html for malicious potential. I might eventualy add [b] tags and such in time for formating.

    Thanks for the help!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I know you're coding in ASP, but in PHP, there's quite a few functions to accomplish this, such as htmlspecialchars() and htmlentities().

    However, I'm pretty sure searching for < and > and replacing them with &lt; and &gt; (respectively) before displaying the message will accomplish the same thing those PHP functions do.

    I'm not sure of syntax, so if you need help, I'm sure someone else will provide you with it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Thank you, I will look into that.
    But what about if the user puts " in their message, isen't that going to throw off my SQL statements?

    Code:
    	strSQL = "";
    	strSQL += "INSERT INTO tblMessages ";
    	strSQL += "(strBody) ";
    	strSQL += "VALUES (' " + strMessage + " ' ");
    Now, lets say strMessage is the Body that the user typed in and is going to be sent to my database through this SQL statement.

    I put extra spaces in the quotes on the last function there just to seperate single and double quotes and make em easier to read.

    So, if was strMessage = ...and then he said, "Hello, world'.

    When passed in as strMessage would that not confuse my SQL Server with the additional " and ' and therefore would result in an error.

    Is there a replacement string like the &lt ect. like you listed above for quotes and double quotes?
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm not sure if it'll mess up the SQL statement...I guess you'll just have to try it. I'm pretty sure PHP takes care of that, although we do have a addslashes() function just in case.

    If there's a replace function, you could just replace all occurances of ' or " with \' and \".

    That should do it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Yes, your right... I could just write a function that scans the users input and replaces 'with \' and \" ect. ect.

    I'm not going to put a resolved in the subject yet because i havent tested it, but i will do so tomorrow.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Again, in PHP there would be escapequotes().

    Maybe you should switch to PHP or JSP
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Maybe you should switch to PHP or JSP
    But I like ASP

    Everything aside, i have to use ASP cause everything has been writen in ASP and the server only runs ASP and SQL. No mySQL or linux. And besides, its a good challenge.
    Last edited by invitro; May 26th, 2003 at 02:29 AM.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Did you get everything working with the replaces?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    I actually haven’t gotten a chance to create a replace function yet. Unfortunately, this week out of many, is a test week and I will probably be at school studying. Got to maintain that GPA. I might sit down and spend a few hours on it tonight when the first one will be over.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

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