Need some help
Posted: Tue Dec 22, 2009 8:54 pm
Hello what im trying to do is add a tiny bit of php to my script, i want to check for no data, then redirect if there is no data, for example the user gets hold of my comments input page code, and finds the "action of the form" points to "comments insert.php" all they have to do is pull up that file and keep refreashing that page, and it will cause blank entrys to my comments display box, so my plan is to redirect out of that page as soon as they try to "false ping it", and so i tried this little code:
if (empty($post))
header("Location: mysite.html");
Works fine, only when i try to send a comment to this script the data gets lost after it passes this code, How can i make it not eat the comment, here is my basic comment php script:
PHP code
------------
<?
$post = $_POST['comments'];
-----------------
if (empty($post)) // i put this little code here, is this correct?
header("Location: mysite.html");
----------------
$words = array('murmer', 'frog', 'bat', '' );
$continue = true;
foreach ($words as $word) {
if (preg_match('/\b' . $word . '\b/i', $post)) {
$continue = false;
header("Location: mysite.html");
exit();
}
}
if (!$continue) {
echo 'Bad boy!';
} else {
$fc = fopen("comments.txt","a+b"); //opens the file to append new comment -
fputs($fc,$_POST['comments']."\n\n\nNewComment->"); //writes the comments followed by a
fclose($fc); //closes the files
if(sizeof($_POST)) {
$body = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}
mail("myemail@myemail.com", // to
"Subject Line",
$body);
header("Location: mysite.html");
}
}
if (empty($post))
header("Location: mysite.html");
Works fine, only when i try to send a comment to this script the data gets lost after it passes this code, How can i make it not eat the comment, here is my basic comment php script:
PHP code
------------
<?
$post = $_POST['comments'];
-----------------
if (empty($post)) // i put this little code here, is this correct?
header("Location: mysite.html");
----------------
$words = array('murmer', 'frog', 'bat', '' );
$continue = true;
foreach ($words as $word) {
if (preg_match('/\b' . $word . '\b/i', $post)) {
$continue = false;
header("Location: mysite.html");
exit();
}
}
if (!$continue) {
echo 'Bad boy!';
} else {
$fc = fopen("comments.txt","a+b"); //opens the file to append new comment -
fputs($fc,$_POST['comments']."\n\n\nNewComment->"); //writes the comments followed by a
fclose($fc); //closes the files
if(sizeof($_POST)) {
$body = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}
mail("myemail@myemail.com", // to
"Subject Line",
$body);
header("Location: mysite.html");
}
}