intenseone345 Posted December 23, 2009 Share Posted December 23, 2009 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 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 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 comment 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"); } } Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/ Share on other sites More sharing options...
dreamwest Posted December 23, 2009 Share Posted December 23, 2009 $post = $_POST['comments']; if (!$post){ header("Location: http://site.com/mysite.html"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/#findComment-982882 Share on other sites More sharing options...
intenseone345 Posted December 23, 2009 Author Share Posted December 23, 2009 Ok, i tried this both ways with the code shown below, but the comment data somehow is gone, instead of just passing by this if there is indeed data present?? can anyone take a shot at why this is?? first code try: ------------- $post = $_POST['comments']; if (!$post){ header("Location: http://site.com/mysite.html"); exit(); } second code try: ---------------- $post = $_POST['comments']; if (empty($_POST)){ header('Location: mysite.html'); } would welcome sugestions, thanks Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/#findComment-983254 Share on other sites More sharing options...
Buddski Posted December 23, 2009 Share Posted December 23, 2009 if (!isset($_POST['comments'])) { // Go away functions // } Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/#findComment-983256 Share on other sites More sharing options...
intenseone345 Posted December 23, 2009 Author Share Posted December 23, 2009 Ok, as not to leave anyone hanging in the air, this code additon was correct: $post = $_POST['comments']; if (!$post){ header("Location: MysiteERROR.html"); exit(); } The problem was this line: $words = array('murmer', 'frog', 'bat', '' ); ---------------------------------------------------- So i changed to this as the word filter was booting the data due to seeing blank space as a rejected word: $words = array('murmer', 'frog', 'bat', ); ---------------------------------------------------- Now it works fine, no more false pings if the end user gets hold of the location of the "postcomment.php file" location, i also back all this up with javascript word filters and empty text box validation, for lots of end user's dont even know what java is, let alone knowing how to turn it off to foil your form, and of coarse php is the best being server side!! Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/#findComment-983293 Share on other sites More sharing options...
dreamwest Posted December 23, 2009 Share Posted December 23, 2009 It should be $words = array('murmer', 'frog', 'bat'); // commas are deliminators aka seperators Quote Link to comment https://forums.phpfreaks.com/topic/186104-need-some-advice/#findComment-983309 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.