adamjones Posted September 18, 2009 Share Posted September 18, 2009 Hi (: I have a really simple code, which I'm using on a basic forum. When a user submits a new thread, or a reply to one, their message is sent to this file, where it is then posted; <?php session_start(); $host="localhost"; $username=""; $password=""; $db_name=""; $tbl_name="questions"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_SESSION['user']; $forum=$_GET['forum']; $datetime=date("d/m/y h:i:s"); if($topic == '') { $errmsg_arr[] = 'You need to give your post a name!'; $errflag = true; } if($detail == '') { $errmsg_arr[] = 'You cant submit a blank message!'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: create_topic.php"); exit(); } $sql="INSERT INTO $tbl_name(title, message, author, datetime, forum)VALUES('$topic', '$detail', '$name', '$datetime', '$forum')"; $result=mysql_query($sql); if($result){ $sql2="UPDATE categories SET last='$topic' WHERE shortname='$forum'"; $result2=mysql_query($sql2); if($result2){ header("location: forums.php?forum=".$forum.""); exit(); }else { header("location: error.php"); exit(); } } ?> What I'm wondering is could a user not submit a hack, or something, which could destroy my database? If anyone knows how, please can you help me protect this, as I have no idea! Also, is it possible to remove HTML submitted? So if a user posts some coding, it is just removed? Thank's for your help! Quote Link to comment https://forums.phpfreaks.com/topic/174743-solved-need-help-protecting-this-please/ Share on other sites More sharing options...
Alex Posted September 18, 2009 Share Posted September 18, 2009 use mysql_real_escape_string() on all input. To remove html you can use strip_tags() Quote Link to comment https://forums.phpfreaks.com/topic/174743-solved-need-help-protecting-this-please/#findComment-920897 Share on other sites More sharing options...
knsito Posted September 18, 2009 Share Posted September 18, 2009 http://www.denhamcoote.com/php-howto-sanitize-database-inputs seems like this is what you want. Always sanitize user input.. any GET POST input for that matter Also good idea to typecast when possible and add 'LIMIT 1' to your SQL Querys when possible on that note: http://lmgtfy.com/?q=php+sanitizing+your+data Quote Link to comment https://forums.phpfreaks.com/topic/174743-solved-need-help-protecting-this-please/#findComment-920898 Share on other sites More sharing options...
adamjones Posted September 18, 2009 Author Share Posted September 18, 2009 http://www.denhamcoote.com/php-howto-sanitize-database-inputs seems like this is what you want. Always sanitize user input.. any GET POST input for that matter Also good idea to typecast when possible and add 'LIMIT 1' to your SQL Querys when possible on that note: http://lmgtfy.com/?q=php+sanitizing+your+data Thankyou very much (: Quote Link to comment https://forums.phpfreaks.com/topic/174743-solved-need-help-protecting-this-please/#findComment-920903 Share on other sites More sharing options...
knsito Posted September 19, 2009 Share Posted September 19, 2009 BTW for HTML tags http://us2.php.net/manual/en/function.strip-tags.php Quote Link to comment https://forums.phpfreaks.com/topic/174743-solved-need-help-protecting-this-please/#findComment-920987 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.