+ Reply to Thread
Results 1 to 5 of 5

Thread: How to avoid Javascript code from entering the database !!

  1. #1
    careerbridge's Avatar
    careerbridge is offline x10 Sophmore careerbridge is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    India
    Posts
    126

    How to avoid Javascript code from entering the database !!

    Hi again,

    When my clients post some data into my site, I need to prevent scripts (javascript codes) from entering my database. Bcose this codes may crack my site.

    If u ppls know any standard method for doing this, please let me know.
    I am using php...

    Jim Jose

  2. #2
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: How to avoid Javascript code from entering the database !!

    Do you currently filter or verify user input at all?

    Javascript code will not be executed unless it is "within" tags such as these:
    Code:
    <script type="text/javascript">  .. </script>
    <script> .. </script>
    <script [other attributes ..]> .. </script>
    I have found that the easiest way to prevent against this is to just strip all HTML/markup tags from a given string. The easiest way to do this is to use the PHP function "strip_tags()", which removes all tags from the supplied arguement.

    With the function you can also specify tags that you do not want to strip, such as "text formatting" HTML tags.

    Example:
    PHP Code:
    <?php
    ..
       
    $userInput '<b>Hey!!</b> <i>Look, this shouldn\'t be here!!</i> <script> alert(\'XSS Hole!!\'); </script>';
       
    $cleanedInput strip_tags($userInput); // Would take *all* tags out of string.
       
    $cleanedInput strip_tags($userInput'<b><i>'); // Would take *all* tags out of string except for the <b> and <i> tag(s).
    ..
    ?>
    Hopefully that is a sufficient answer for you.. Let me know if you need something else or what not.
    Last edited by Bryon; 06-18-2006 at 09:57 AM.

  3. #3
    careerbridge's Avatar
    careerbridge is offline x10 Sophmore careerbridge is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    India
    Posts
    126

    Re: How to avoid Javascript code from entering the database !!

    Ok I got it.... thanks a lot Bryon !! That was exactly what I need !! ;)

  4. #4
    IncarcerationX's Avatar
    IncarcerationX is offline x10Hosting Member IncarcerationX is an unknown quantity at this point
    Join Date
    May 2006
    Posts
    11

    Re: How to avoid Javascript code from entering the database !!

    Make sure you only put these tags in places where users are allowed to input data. If you put that code snippet into the wrong place, it could screw up your entire website.

    ^^Clicky for my GFX

  5. #5
    careerbridge's Avatar
    careerbridge is offline x10 Sophmore careerbridge is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    India
    Posts
    126

+ Reply to Thread

Similar Threads

  1. Hybrid's HTML Lessons
    By Hybrid in forum Tutorials
    Replies: 18
    Last Post: 11-28-2009, 02:12 PM
  2. PHP BB 2.0.16 Manual instalation
    By GFIV in forum Free Hosting
    Replies: 8
    Last Post: 09-14-2005, 12:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers