Jump to content

strip_tags


madcrazy

Recommended Posts

Hello everyone!  :o Client API version  5.0.24  php 4.4.7

 

I am trying to make code that will let users upload images and embeded

object tags via a simple web form. I have it working correctly, it does what i want it to:

user uploads say <img src="http://blabla"> from a web form.

it gets dumped into the sql table.

 

this is the "behind the scenes" code that works on the form submission:

 

case "Images": {

## VALIDATE FORM ENTRY:

if (get_magic_quotes_gpc()==0) {

$V1 = filter_str(strip_tags($_POST['V1']),$connector)

$V2 = filter_str(strip_tags($_POST['V2']),$connector);

}

## ADD ENTRY INTO DATABASE:

$query_add="INSERT INTO `tbl_mytable` (`uid` , `name` , `bigimage` )

VALUES ('".$_SESSION['uid']."', '$V1', '$V2')";

$result=mysql_query($query_add);

$_REQUEST['page'] = "Images";

$ErrorMessage = "Image updated successfully";

}break;

 

 

 

then it is retrieved via a webpage with this query:

<?

  ## GET INFORMATION

$RunThisQuery = "SELECT id, bigimage  FROM files WHERE uid=".$_REQUEST['id'];

$results = $connector->query($RunThisQuery);

while ($row = $connector->fetchArray($results)){

  ?>

<a href="<? print $row['bigimage']; ?>"></a>

<? } ?>

 

 

i had to set get_magic_quotes_gpc()==0

in order to upload the tags, otherwise setting to 1 strips them away.

the problems i have with this are:

1.)Any code can be submitted, i am not aware of the kind of code

that could be submitted that could potentially breach security/privacy

or damage my whole website. but just to be sure i would like to

be able to have users upload using this form, but only strip away potentially

dangerous code from getting into the database.

Can someone please help. Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/53680-strip_tags/
Share on other sites

Greetings, Im assuming your saying that is someone sends a <script tag

this is really the only thing that could harm my website(besides appearance wise). please correct me if i am wrong.

Also. could this solution be implemented by just adding the script tags like so..

 

 

<?

    ## GET INFORMATION

  $RunThisQuery = "SELECT id, bigimage  FROM files WHERE uid=".$_REQUEST['id'];

  $results = $connector->query($RunThisQuery);

  while ($row = $connector->fetchArray($results)){     

  ?>

<a href="<sc2ript <? print $row['bigimage']; ?>scrip2t>">[/url]

    <? } ?>

 

Is this what you mean?

i had already nested the output in an href , was not sure this would work also.

 

thank you~

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/53680-strip_tags/#findComment-265683
Share on other sites

If the above is not a solution, i have found this bit of code:

function html2txt($document){

$search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript

              '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly

              '@<![\s\S]*?--[ \t\n\r]*>@'        // Strip multi-line comments including CDATA

);

$text = preg_replace($search, '', $document);

return $text;

}

 

but i dont know how to integrate this code with:

 

if (get_magic_quotes_gpc()==1) {

$V1 = filter_str(strip_tags($_POST['V1']),$connector)

$V2 = filter_str(strip_tags($_POST['V2']),$connector);       

  }

 

At one point I actually took out this whole thing:

if (get_magic_quotes_gpc()==1) {

$V1 = filter_str(strip_tags($_POST['V1']),$connector)

$V2 = filter_str(strip_tags($_POST['V2']),$connector);       

  }

to make the code work, but this just caused everything not to work

so i just changed get_magic_quotes_gpc()==0

it worked but doesnt strip anything

 

Link to comment
https://forums.phpfreaks.com/topic/53680-strip_tags/#findComment-265763
Share on other sites

Can you help me with implementing this please:

function html2txt($document){

$search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript

              '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly

              '@<![\s\S]*?--[ \t\n\r]*>@'        // Strip multi-line comments including CDATA

);

$text = preg_replace($search, '', $document);

return $text;

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/53680-strip_tags/#findComment-265775
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.