Jump to content

Need some advice


intenseone345

Recommended Posts

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");

}

 

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!

 

Link to comment
Share on other sites

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.