Jump to content

How can I prevent Javascript coding?


frank_solo

Recommended Posts

I've been alerted that someone can attack my site using XSS. I have a search box on my site and I've tested it by simply writing "<script>alert('test')</script>" When I do this a pop-up box does come up displaying the word "Test" I have written a preg_replace previously but now I want to add something to it to prevent <script>.

 

This was my original code

$search = mysql_real_escape_string(preg_replace('/[^\w\'\"\@\-\.\,\(\) ]/i', '', " $_POST['search']));

 

This is what I thought might work but no luck

$search = mysql_real_escape_string(preg_replace('/[^\w\'\"\@\-\.\,\(\) ]/i', '', "/<script[^>]*>.*<*script[^>]*>/i", $_POST['search']));

 

Could anyone please help and tell me how to modify the code to prevent javascript?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/249036-how-can-i-prevent-javascript-coding/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.