Jump to content

Recommended Posts

Hi everyone,

 

 

If you know a way to block comments that have HTML in them, then please PM me. Someone just posted a comment that made the site redirect to goatse.ch...  :wtf:

 

 

Please help!!  :facewall:

 

 

P.S. I've already deleted the comment with HTML in it and I have disabled comments.

Link to comment
https://forums.phpfreaks.com/topic/268669-delete-all-html-in-comments/
Share on other sites

There's more than one way to skin this cat: htmlspecialchars(), strip_tags(), htmlentities(), etc. would all do the job.  Some people like to do it before inserting into DB, other like to do it while printing the content out.

 

http://www.php.net/strip_tags

http://www.php.net/htmlspecialchars

http://www.php.net/htmlentities

htmlspecialchars () is definitely the way to go. htmlentities () is quite unnecessary as it does too much, and strip_slashes () is not recommended because you're just as likely to remove legit content with it.

 

However, this doesn't alleviate the need to Validate the Input you get from the user. The above methods are only Escaping Output, after all. Input validation is a quite wide and potential complex topic, so I recommend reading a few guides on how to do this.

Okay, here's my commentstream.php code:

 

 






<?php
('includes/db_connect.php');
$result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 10");
htmlspecialchars ()
while($row = mysql_fetch_array($result))
  {
  echo "<div class='comment'><b><center>".$row['username'] . "</b></center><br><br><center><i>" . $row['comment']."</i></center><>";
  echo "<br/>";
  }
  ?>




 

 

 

 

Error:Parse error: syntax error, unexpected T_WHILE in /home/a1922355/public_html/commentstream.php on line 5

Your call to htmlspecialchars() isn't necessary and shouldn't be there without being used. Check the PHP Manual..

<?php
('includes/db_connect.php');
$result = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 10");
htmlspecialchars ()  // <--- Why is this even here? It's not being called right, not ending with a ; .  
while($row = mysql_fetch_array($result))
 {
 echo "<div class='comment'><b><center>".$row['username'] . "</b></center><br><br><center><i>" . $row['comment']."</i></center><>";
 echo "<br/>";
 }
 ?>

Hello all...

 

I am working on a website, but I have a comments system and my 'good' ole friend is using HTML redirects...

-_-

 

 

So, I am trying to delete all code that shows up in comments. Basically what I want to do is have it so that <b> = [bLOCKED].

 

Here's my code:

<meta http-equiv="Refresh" content="0;url=home.php" />
<?php
include('includes/db_connect.php')

$username = mysql_real_escape_string($username);
$comment = mysql_real_escape_string($comment);

mysql_query("INSERT INTO comments (username, comment) VALUES ('$_POST[username]','$_POST[comment]')");
?>

 

Thanks! :tease-01:

You best bet is to use Regex for this..so I´m moving this to that forum.

 

Moving back, this is not a regex problem at all. As jesi pointed out, it was already answered in his original post.

 

Edit:

Looks like gurus cannot move anymore. Either or, it is not a regex issue.

Edited by premiso
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.