Jump to content

Recommended Posts

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

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.

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.