Jump to content

quick question


turkman

Recommended Posts

a simple way could be...

<?php

$string="<script type='text/javascript'>alert('blah');</script>";

$string=str_replace("script", "", $string);
?>

 

Simple yes, but also easy to circumvent, I think.  Try using strip_tags(), addslashes(), and a few str_replace() to remove key words usually associated with script code. I think you should probably use the function (I forget it's name) that converts all ascii character representations into their actual characters before doing the above steps.

Link to comment
https://forums.phpfreaks.com/topic/112660-quick-question/#findComment-578628
Share on other sites

Its basically a basic forum and i was just doing some debuging and if i enter that javascript script into the text area and submit it, when i open the thread it opens an alert box. I figured php would have a function, is there anything that parses html in php or do i need to write one myself? basically just get it to ignore everything between the <> before i add it to a database.

 

 

Link to comment
https://forums.phpfreaks.com/topic/112660-quick-question/#findComment-578907
Share on other sites

Its basically a basic forum and i was just doing some debuging and if i enter that javascript script into the text area and submit it, when i open the thread it opens an alert box. I figured php would have a function, is there anything that parses html in php or do i need to write one myself? basically just get it to ignore everything between the <> before i add it to a database.

 

 

 

strip_tags("<  b>< i >< hr>..etc", $string); will do that for ya(without the spaces within the tags). But I read somewhere that there are ways around it... not sure what those ways are though

Link to comment
https://forums.phpfreaks.com/topic/112660-quick-question/#findComment-578913
Share on other sites

Yeah, if you include the tags in strip_tags() I believe it will remove the tags, however if a user add a parameter to the tag, this will not be recognised and therefore not removed. If you want actual security I would recommend not adding that extra parameter.

 

Anyway, you're probably better off using htmlentities() or htmlspecialchars() as this was you will be able to see what HTML people are trying to enter without just removing it totally and never knowing if people are trying to inject you.

Link to comment
https://forums.phpfreaks.com/topic/112660-quick-question/#findComment-579002
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.