user892134
user892134

Reputation: 3224

htmlentities or htmlspecialchars or stripslashes? Which one to use?

When i insert user input data into the mysql database i use, mysql_real_escape_string. The input data contains bbcode e.g. [img][/img].

Below is a line for when the html is output.

    $information = $this->bbcode(stripslashes($this->swearfilter($row['information'])),1);
   echo $information;

Regarding this example, is this the correct way to prevent a XSS attack or do i use htmlspecialchars($var,ENT_QUOTES) or htmlentities?

Upvotes: 0

Views: 1467

Answers (2)

Ganesh Bora
Ganesh Bora

Reputation: 1153

$message = preg_replace('#\[img\](.*?)\[/img\]#', '<img src="$1" />', $message);  

Prevent XSS Attacks

Upvotes: 0

swapnesh
swapnesh

Reputation: 26732

use htmlspecialchars() to prevent XSS attack

Upvotes: 2

Related Questions