Htmlspeacialchars

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Htmlspeacialchars

    hey guys, im sitting with a prob. everytime a member adds text with the & symbol, and displays the text he has added, an error occurs. what is the problem

    #2
    is there a security Vulnerability if i add the following code at the top of my script
    Code:
    $txt = $_POST["txt"];
    $txt = str_replace('&', "&", $txt);
    $txt1 = htmlspecialchars($txt);
    $result = mysql_query("INSERT INTO text_table SET message='".$txt1."'");

    Comment


      #3
      yes so use it
      Code:
      $txt = mysql_real_escape_string($_POST["txt"]);
      $txt = str_replace('&', "&", $txt);
      $txt1 = htmlspecialchars($txt);
      $result = mysql_query("INSERT INTO text_table SET message='".$txt1."'");

      Comment


        #4
        but what will happen if i use your code. its the same as mine

        Comment


          #5
          mine is secured and yours is vulnerable.so use mine and google for mysql_real_escape_string() or mysql_escape_string()

          Comment


            #6
            where would i place this code? must i place it where ever text is entered and sent to db

            Comment


              #7
              i need someone to help me understand htmlspecialchars:

              correct me if im wrong....
              example
              i add an address http://domain.com/ref=2&id=1 in a submit form (datatosend.php),
              the address is then posted to (procdata.php) where the page looks like this
              Code:
              else if($action=="addaddy")
                      {
                      $addy = mysql_real_escape_string($_POST["addy"]);
                      $addy= str_replace('&', "&", $addy);
                      {
                       echo head($thm);
                       echo pc();
                       $addy1 = htmlspecialchars($addy);
                       $result = mysql_query("INSERT INTO address SET addy='".$addy1."'");
                  
                       if($result)
                                 {
                                 echo "Address Added Successfully";
                                 }
                                      
                       else
                                {
                                 echo "Database Error!
              ";
                                 echo "Please contact the administrator";
                                 }
                       }
              echo homelink($ses);
              echo pe();
              echo foot();
                       }
              http://domain.com/ref=2&id=1 is posted to this form and string & is then replaced by & and then what happens at htmlspecialchars function. as far as i know after it has passed all functions it is then sent to the db

              Comment


                #8
                why not just use the string replace function:
                txt = hello & goodbye

                $txt = str_replace("&","&",$txt);

                then call from db

                echo "$txt";

                and the following is displayed: hello & goodbye.

                Comment

                Working...
                X