Warptweet Posted April 2, 2007 Share Posted April 2, 2007 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 More sharing options...
per1os Posted April 2, 2007 Share Posted April 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/45215-block-coding-languages/#findComment-219528 Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 PHP code will not be executed when posted through a form, well, not unless you've gone and done something pretty silly with eval. Link to comment https://forums.phpfreaks.com/topic/45215-block-coding-languages/#findComment-219534 Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 the best way to handle javascript input is to never echo out user input without cleaning it first Link to comment https://forums.phpfreaks.com/topic/45215-block-coding-languages/#findComment-219549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.