Hi im really just a newb here but i need help form a pro i did a bit of reading of how to secure my code form all the nasty kinds of attack so i did remove slashes on stuff and mysql_real_escape_string on all posts to the server i hope. Well please tell me if this will provide adequate protection and error handling.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>New form topic</title>
<?php
///start session
include("include/session.php");
//////constants
$username = $session->username;
$usrname = $session->username;
$numbers = $database->getNumMembers();
///stylesheet
include("stylesheet/stylesheet.php");
///javascripts
?>
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce_gzip.js"></script>
<script type="text/javascript">
tinyMCE_GZ.init({
plugins : 'style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras',
themes : 'simple,advanced',
languages : 'en',
disk_cache : true,
debug : false
});
</script>
<!-- Needs to be seperate script tags! -->
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "table,advimage,advlink,emotions,iespell,insertdatetime,preview,zoom,flash,searchreplace,contextmenu",
theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add : "iespell,flash,advhr",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
plugin_insertdate_dateFormat : "%Y-%m-%d",
plugin_insertdate_timeFormat : "%H:%M:%S",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
external_link_list_url : "example_data/example_link_list.js",
external_image_list_url : "example_data/example_image_list.js",
flash_external_list_url : "example_data/example_flash_list.js"
});
</script>
</head>
<body>
<div id="container">
<?php
///header
include('includes-blocks/header.php');
?>
<div id="Layer_content">
<div id="content_outer">
<div class="pageheader">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td class="title">New form topic</td>
</tr>
</table>
</div>
<table width="100%" border="1" cellspacing="2" cellpadding="0">
<tr>
<td width="20%" valign="top">
<?php
include('includes-blocks/whosonline.php');
?>
</td>
<td width="80%" valign="top">
<?php
///logged in
if($session->logged_in)
{
///get constants
///error filtering
$title = stripslashes($_GET['title']);
if(is_numeric($_GET['category'])) {
$topic = $_GET['category'];
} else {
echo "Category is not numeric, Please return to the forum and try again";
}
///// if page has errors
if (!isset($_GET['subpage'])) {
?>
<form name="story" action="new_forum_topic.php?subpage=upload&category=<?php echo $topic ?>&title=<?php echo $title ?>" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0" >
<tr class="page_title"><td width="70%">Add new topic</td><td width="15%"></td><td width="15%"></td></tr>
<tr class="page_contrast"><td width="70%"><input type="submit" value="Post Topic"> | <a href="forum_topic.php?id=<?php echo $topic ?>&title=<?php echo $title ?>">Back to forum</a></td><td width="15%"></td><td width="15%"></td></tr>
<tr class="page_contrast"><td width="70%">Title: <input type="text" size="35" name="subject"/></td><td width="15%"></td><td width="15%"></td></tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
<tr class="mail_bcknd">
<td width="10%"></td>
<td width="80%">
<textarea name="post" rows="15" cols="80"></textarea>
</form>
</td>
<td width="10%"></td>
</tr>
</table>
<?php
}
else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {
////constants////
$subject = stripslashes($_POST['subject']);
$post = stripslashes($_POST['post']);
///set up time
date_default_timezone_set('Europe/London');
$today = date("F j, Y, g:i a");
////error checking
if ($subject == "" or $post == "") {
?>
<form name="story" action="new_forum_topic.php?subpage=upload&category=<?php echo $topic ?>&title=<?php echo $title ?>" method="post">
<table width="100%" border="0" cellpadding="3" cellspacing="0" >
<tr class="page_title"><td width="70%">Add new topic</td><td width="15%"></td><td width="15%"></td></tr>
<tr class="page_contrast"><td width="70%"><input type="submit" value="Post Topic"> | <a href="forum_topic.php?id=<?php echo $topic ?>&title=<?php echo $title ?>">Back to forum</a></td><td width="15%"></td><td width="15%"></td></tr>
<tr class="page_contrast"><td width="70%"><?php
if ($subject == "") {
echo "<font class=\"error\">You seem to have forgotten to add the subject of your post</font>";
}
?></td><td width="15%"></td><td width="15%"></td></tr>
<tr class="page_contrast"><td width="70%">Title: <input type="text" name="subject" value="<?php echo htmlentities($subject); ?>"/></td><td width="15%"></td><td width="15%"></td></tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
<tr class="mail_bcknd">
<td width="10%"></td>
<td width="80%">
<?php
if ($post == "") {
echo "<font class=\"error\">You seem to have forgotten to add the content of your post</font>";
}
?>
</td>
<td width="10%"></td>
</tr>
<tr class="mail_bcknd">
<td width="10%"></td>
<td width="80%">
<textarea name="post" rows="15" cols="80"><?php echo htmlentities($post); ?></textarea>
</form>
</td>
<td width="10%"></td>
</tr>
</table>
<?php
////end the error checking
}
/////uploader component////
else {
////error handling
$topic_subject = stripslashes($_POST['subject']);
$bodytext = stripslashes($_POST['post']);
if(is_numeric($_GET['category'])) {
$category = $_GET['category'];
} else {
echo "Category is not numeric, Please return to the forum and try again";
}
////the uploading process/////
$sql = sprintf("INSERT INTO `forum-posts` (`post-id`, `username`, `date`, `subject`, `post`, `lastpost`, `lastposttime`) VALUES ('%d', '%s', '%s', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($category),
mysql_real_escape_string($username),
mysql_real_escape_string($today),
mysql_real_escape_string($topic_subject),
mysql_real_escape_string($bodytext),
mysql_real_escape_string($username),
mysql_real_escape_string($today));
$query = mysql_query($sql);
if(!$query) {
///// error out /////
echo "There was an error, please try again.";
}
else
?>
<table width="100%" border="0" cellpadding="3" cellspacing="0" >
<tr class="page_title"><td width="70%">Uploaded</td><td width="15%"></td><td width="15%"></td></tr>
</table>
<table width="100%" border="0" cellpadding="3" cellspacing="0" >
<tr>
<td width="15%" class="mail_bcknd"></td>
<td width="70%">
<p style="margin-bottom: 13pt" class="MsoNormal"><span style="color: #242424; font-family: ArialMT" class="Apple-style-span">Thank you very much for contributing.</span></p><p style="margin-bottom: 13pt" class="MsoNormal"><span style="color: #242424; font-family: ArialMT" class="Apple-style-span">You may now go back to the forum page. Or any other page ^_^</span></p>
</td>
<td width="15%" class="mail_bcknd"></td>
</tr>
<tr class="mail_bcknd">
<td width="15%" class="mail_bcknd"></td>
<td width="70%" align="center">
<p style="margin-bottom: 13pt" class="MsoNormal"><span style="color: #242424; font-family: ArialMT" class="Apple-style-span"><a href="forum.php">Back to forum</a> | <a href="forum_topic.php?id=<?php echo $topic ?>&title=<?php echo $title ?>">Back to <?php echo $title; ?></a></span></p>
</td>
<td width="15%" class="mail_bcknd"></td>
</tr>
</table>
<?php
/////////////////update forum lastpost/////////////
///// removed slashes form the category
$post_subject = stripslashes($_POST['subject']);
if(is_numeric($_GET['category'])) {
$category = $_GET['category'];
} else {
echo "Category is not numeric, Please return to the forum and try again";
}
////error handling/////
$find_subject = stripslashes($_POST['subject']);
////load the last record for update//////
$sql = sprintf("SELECT * FROM `forum-posts` WHERE `subject` = '%s'",
mysql_real_escape_string($find_subject));
$query = mysql_query($sql);
$row = mysql_fetch_row($query);
$number = "$row[0]";
/////update the topic headings with the new data///
$sql = sprintf("UPDATE `forum-topics` SET `lastpost`='%s', `lastposttime`='%s', `lasttopic`='%s', `lastid`='%s' WHERE `id` = '%s'",
mysql_real_escape_string($username),
mysql_real_escape_string($today),
mysql_real_escape_string($post_subject),
mysql_real_escape_string($number),
mysql_real_escape_string($category));
$query = mysql_query($sql);
if(!$query) {
///// error out /////
echo "There was an error, please try again.";
}
}
}
}
else {
readfile("includes-blocks/frontpage.html");
}
?>
</td>
</tr>
</table>
</div>
<div id="footer">
<img src="images/header/page_footer.png" alt="footer" />
</div>
</div></div>
</body>
</html>
updated with latest code.
updated 2, added htmlentities to the displayed post.