Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How Good Is This Data Cleaning Function?
shadowx
post Feb 4 2007, 12:18 PM
Post #1


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



Hi all, this is my first function and as part of a script and i just want to know a couple of things.

here is the code for the function:

CODE
<?

function clean($dirty_string) {

$muddy_string = stripslashes($dirty_string);

$murky_string = strip_tags($muddy_string);

$clean_string = htmlentities($murky_string);
    
};

?>


So the first thing is how secure is it? the script this will be used in connects to a database and sends an email so it needs to stop SQL injections and any email abuse it might cause, also the data stored in the database will be usaed as part of a HTML page so it needs to be HTML proof which is why i used HTMLENTITIES and of course STRIP_TAGS gets rid of php and HTML so was a good choice i thought.

That is all really! If its not that secure then are there any other built in functions i could add?

Thanks
Go to the top of the page
 
+Quote Post
cooleappie
post Apr 28 2008, 07:07 PM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 13
Joined: 12-April 08
Member No.: 60,713



As far as i can see, is it for that purpose good enough.. If it would be for a very important part which other persons may in no case enter, i would add more.. but this is enough for this..
Go to the top of the page
 
+Quote Post
galexcd
post Apr 28 2008, 07:50 PM
Post #3


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
*********

Group: [HOSTED]
Posts: 975
Joined: 25-September 05
From: The dungeon deep below the foundation of trap17
Member No.: 12,251



It is pretty good, I just have a couple of quick suggestions to add. First of all why are you wasting memory on the server with all of those useless variables? Even though its temporarily while your page is loading. Normally for code this short it wouldn't matter, but since its a function that will be included in other pages, the object of it is to be fast and effective. The faster and more effective it is the better the function is.

Also I assume the reason you have htmlentities after strip_tags is to parse '<' and '>' that are not in tag format? (for example an arrow: -->). If you are doing this why do you also strip_tags? Is it important to completely eliminate tags that are in html format? Why not just keep them in there and just parse them into &gt; and &lt;?

Also, I would think that add_slashes would make it more secure than strip_slashes. This would escape out quotes, and would also escape out any backslashes that strip_slashes would remove, rendering them useless.

This post has been edited by alex7h3pr0gr4m3r: Apr 28 2008, 07:53 PM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Getting List Of Directories And Files Using Php(6)
  2. php header() function help needed(4)
  3. Finding Data In Meta Tags(0)
  4. How To Use A Link To Call Function In Php?(8)
  5. Include File.php?id=something(13)
  6. How To Enable Mail() Function In Php(1)
  7. Question About The Mail() Function(2)
  8. Same 1 Registeration Data For Different Purposes(4)
  9. Loading Mysql Data Into A Table(10)
  10. Regexp Function Preg_match_all()(0)
  11. Explode Function Help(1)
  12. The Extract() Function(6)
  13. Error With Joomla Template(1)
  14. Putting Data Of 2 Pages In Mysql At Once(1)
  15. Problems With Data Formatting(2)
  1. What Does This Do?(4)
  2. [php] Header Function(2)
  3. [php](simple) Using Functions To Combine Values In A Form(2)
  4. Mail() Clone(5)
  5. The Best Zip Function(1)
  6. Php Explode Function Help(4)
  7. Using Multiple Selection Array In Table To Order Data(1)
  8. How To Check If Fsockopen Function Is Enabled?(2)
  9. Arrays Outside A Function(3)
  10. Php Email Validation(1)
  11. Php + Mysql Question!(4)
  12. Endif function?(6)
  13. PHP Function To Add Previous and Next Page Feature(0)


 



- Lo-Fi Version Time is now: 25th July 2008 - 08:52 PM