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
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
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
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
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.