runnerjp Posted November 9, 2008 Share Posted November 9, 2008 im using bbcode and wonderd how to make the code safe from injection... here is my code <?php $thedate = date("U"); //get unix timestamp $displaytime = time(); //This is where the bbcode come in. $message = new BBCode; $message->selection = $yourpost; $message->parseCode(); // set to 1 if you want to disable bbcode $message->parseEmoticons(); $yourpost = $message->parsed; $insertpost = "INSERT INTO `forumtutorial_posts` (`author`,`forum`,`title`,`post`,`showtime`,`realtime`,`lastposter`,`parentid`) values('$name','$forum','$subject','$yourpost','$thedate','$thedate','$name','$forumpostid')"; mysql_query($insertpost) or die("Could not insert post"); //insert post $updatepost = "UPDATE `forumtutorial_posts` SET `numreplies`=`numreplies`+'1', `lastposter`='$name', `lastrepliedto`='$thedate' WHERE `postid`='$forumpostid'"; mysql_query($updatepost) or die("Could not update post"); $updatep = "UPDATE `users` SET `post_count`=`post_count`+'1', last_post=$thedate WHERE `Username`='$name'"; mysql_query($updatep) or die("Could not update post"); header("Location: http://www.runningprofilfes.com/members/index.php?page=message&forum=$forum&id=$forumpostid");?> Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/ Share on other sites More sharing options...
.josh Posted November 9, 2008 Share Posted November 9, 2008 maybe, maybe not. You're inserting/updating with a bunch of vars but you do not show where they are coming from. Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686089 Share on other sites More sharing options...
premiso Posted November 9, 2008 Share Posted November 9, 2008 You should really check the variables you are going to be running SQL on for the SQL injection. I do not see anywhere in this code where that is done. On top of that you should use www.php.net/mysql_real_escape on variables before you use them in the SQL. This will parse the code and take care of anything that could be SQL injected. I am sure searching the forums will bring up alot on SQL injection and the best practices to make sure your code is safe. From what is shown here, you are not safe. Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686090 Share on other sites More sharing options...
runnerjp Posted November 9, 2008 Author Share Posted November 9, 2008 alot of the vars are coming from the db so im saying they will be ok... but $yourpost = $_POST['yourpost']; $subject = $_POST['title']; come from a poist but would adding real_escape stop the bbcode beeing used? Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686096 Share on other sites More sharing options...
premiso Posted November 9, 2008 Share Posted November 9, 2008 No adding real escape will not stop the BBCode from being used. All it does is escape characters that mysql uses and takes them literally. Sort of like in PHP you would use a / to escape a quote so it will display properly on the page and not throw an error in the code. Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686098 Share on other sites More sharing options...
Andy-H Posted November 9, 2008 Share Posted November 9, 2008 $yourpost = mysql_real_escape_string($_POST['yourpost']); $subject = mysql_real_escape_string($_POST['title']); Use post data for queries like that.. Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686099 Share on other sites More sharing options...
runnerjp Posted November 9, 2008 Author Share Posted November 9, 2008 ahh right well that has helped alot.. iv miss understood what i had learnt lol ty guys! Link to comment https://forums.phpfreaks.com/topic/132032-is-this-code-safe-form-sql-injection/#findComment-686107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.