Jump to content

Block Coding Languages?


Warptweet

Recommended Posts

I use this (currently inneficient way) code to stop PHP and Javascript from being entered in $blog_text

 

$blog_text = str_replace("<?PHP", "PHP Permissions Denied", $blog_text);

 

For PHP, it easily works because the <?php it's absolutely vital to start php (I didn't enable the ability to start php with <?)

 

But Javascript does not REQUIRE <script language="text/javascript"> as far as some pesky visitors did, they ended up making one of their blogs with unstoppable music, popups, text alerts, it was sick.

 

Javascript MUST BURN!!!!

Is there a way in a SINGLE LINE to simply completely BLOCK javascript from being enabled on the page?

If not, what is a better method of blocking javascript?

Link to comment
https://forums.phpfreaks.com/topic/45215-block-coding-languages/
Share on other sites

There are a few ways. One way is to convert all < to < this is will disallow the scripts to be ran. Or simply convert <script to <script

 

IE:

 

if (eregi('<script', $blog_text)) {
     $blog_text = str_replace('<script', '<script', $blog_text);
}

 

That would work for not letting it run. But you can also parse it out. IE: You know js must have the </script> to work so do this.

 

<?php
$blog_text = 'This is a test <script language="text/javascript"> this is some alert(\'javascript\');</script> some after math text <script> smores?</script>  here is some more';

if (eregi('<script', $blog_text)) {
     while (eregi('<script', $blog_text)) {
         list($before, $javascript) = spliti("<script", $blog_text, 2);
         list($javascript, $after) = spliti("</script>", $javascript, 2);
         $blog_text = $before . " Javascript Denied " . $after;
     }
}

print "<pre>" . $blog_text . "</pre>";
?>

 

Should suffice either way you want.

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.