Bman900 Posted February 16, 2010 Share Posted February 16, 2010 I know you guys said this many times before but what do you have to attach to a form so people can't inject harmful code? Quote Link to comment https://forums.phpfreaks.com/topic/192318-prevent-textbox-injections/ Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 You cannot ban them from injecting harmful code, but you can stop the code from running. For example, if the text box is to be for a user's name, chances are they will not need to enter any html tags, so a simple strip_tags will prevent an XSS exploit and if it is going into the database, filtering the data or at least mysql_real_escape_stringing the data will prevent SQL Injection. For a more thorough description see this PHP Security Tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/192318-prevent-textbox-injections/#findComment-1013444 Share on other sites More sharing options...
Bman900 Posted February 16, 2010 Author Share Posted February 16, 2010 So can I just use mysql_real_escape_string() on all my text boxes instead of the strip tags? Quote Link to comment https://forums.phpfreaks.com/topic/192318-prevent-textbox-injections/#findComment-1013446 Share on other sites More sharing options...
premiso Posted February 16, 2010 Share Posted February 16, 2010 So can I just use mysql_real_escape_string() on all my text boxes instead of the strip tags? Read the tutorial. But as I said, strip_tags will prevent XSS exploits, if the text box is not suppose to contain HTML / JavaScript. XSS exploits is basically someone writing javascript code that gets run on the page which can inject cookies / redirect users to certain pages etc. Those 2 functions prevent 2 seperate items. If you are allowing HTML (not to be executed) in a textbox, you will want to look into htmlentities. Since this has been hit so many times, and I have given you the terms to search for, I will not go into greater detail on how to "secure" your script. Look at the tutorial I posted and google "prevent xss php" for more information. You can read and do research as well as I can, and since you are the one who wants to learn this, I will let you do the research. Quote Link to comment https://forums.phpfreaks.com/topic/192318-prevent-textbox-injections/#findComment-1013448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.