DeathStar Posted March 22, 2007 Share Posted March 22, 2007 Hi there.. What is the most secure way to protect yourself from SQL injections? I searched google and ony found programs ect.. Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/ Share on other sites More sharing options...
trq Posted March 22, 2007 Share Posted March 22, 2007 Use mysql_real_escape_string and allways validate your data. Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212710 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 so: $username = mysql_real_escape_string($_POST['user']); $password = mysql_real_escape_string($_POST['pass']); would be safe? Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212724 Share on other sites More sharing options...
monk.e.boy Posted March 22, 2007 Share Posted March 22, 2007 $safe_username = mysql_real_escape_string($_POST['user']); $safe_password = mysql_real_escape_string($_POST['pass']); Yes. Add 'safe' to stuff you are sure is safe. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212798 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 It's important to check if you have magic_quotes enabled before escaping- you dont want to escape your data twice... <?php $safe_username = sql_quote($_POST['user']); $safe_password = sql_quote($_POST['pass']); function sql_quote($str) { if(get_magic_quotes_gpc()) $str = stripslashes($str); return mysql_real_escape_string($str); } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212801 Share on other sites More sharing options...
gazalec Posted March 22, 2007 Share Posted March 22, 2007 another good idea is to have a white list so if you are specifically looking for a username, access your database, grab all your usernames add them into an array and then check the input with the array and if they dont match you can use the location function to redirect them to another page without their input affecting your database Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212806 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 ok.. Link to comment https://forums.phpfreaks.com/topic/43818-sql-injections/#findComment-212811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.