-1

Please help me.. I have a contact form page and thank you page. I just want to restrict my thank you page and it can only access after submit action on contact form click. So how can I do that? Thank you! :)

EX:

If directly access the thankyou.php ex: (localhost/test/thankyou.php). it automatic redirect on index.php.

And thankyou.php can only access after clicking the submit button or action on contact form.

Ron Cortez
  • 11
  • 1
  • Check if there is data in `$_POST` – zerkms Jan 07 '15 at 07:16
  • First for contact form security, u should use google recaptcha api ( it avoids unwanted hits like bots) and also use ` $_POST ` or ajax check in php... And for more security, use ` $_SESSION['flag'] ` :) – Shahzad Barkati Jan 07 '15 at 07:41

2 Answers2

1

Rather simple, replace $_POST with the type you are using ($_POST / $_GET)

<?php

if(!isset($_POST)){
    header('Location:URLHERE');
    die();
}

 <<START/REST OF YOUR THANK YOU CODE/PAGE>>
?>

If you want to you can also check for a specific variable / name is set. Again replace the $_POST with the type you are using. ($_POST / $_GET) - Along with the variable to check for of course :)

<?php

if(!isset($_POST['name'])){
    header('Location:URLHERE');
    die();
}

 <<START/REST OF YOUR THANK YOU CODE/PAGE>>

?>
Epodax
  • 1,828
  • 4
  • 27
  • 32
0

the easiest way is to have a hidden field on your form maybe called "form-sent" for example with value "yes". thrn on your thankyou page use an if statement to check this field is in $_POST along with the value:

if(isset($_POST["form-sent"]) && $_POST["form-sent"] == "yes"){

}

just a badsic example. you could in fact check it does not exist or the value is not "yes" and redirect back off the page.

sorry for poor formatting i posted on my phone.

PHP Addict
  • 136
  • 5