Use sessions to create a disclaimer and agreement page

I am trying to create a page with a Disclaimer and Agreement in WordPress/PHP.

Disclaimer:

Read More
  1. If users select ‘UK’ from a dropdown, they are sent to an Agreement page.
  2. If users select any other country, they are sent to an ‘Access Denied’ page.

Agreement:

  1. If the user clicks “I agree” they are sent to the final stage “Well Done”.
  2. If the user clicks “Disagree” they are sent to the ‘Access Denied’ page.

I’ve come up with the following, but the select options are not working and I’m not sure how to direct all countries except the UK to an access denied page.

Any ideas what I am doing wrong?

<?php 

session_start();
if(!isset($_SESSION['grant_access'])) {
        $_SESSION['grant_access'] = ‘unset’;
}

if(isset($_POST['United Kingdom'])) {
        $_SESSION['grant_access'] = ‘partialset’;
}

if($_SESSION['grant_access'] == ‘partialset’) { ?>
 '<p>You are nearly there. Now you must agree.</p>';
    <form method="post">
        <form method="post">
                <input type="submit" value="I Agree" name="agree" />
        </form>
<?php 
}

if($_SESSION['grant_access'] == ‘unset’) {
?>
        <h1>Disclaimer.</h1>
        <p>Choose your country.</p>

        <form method="submit">
          <select>
            <option value="Australia" title="Australia">Australia</option>
            <option value="France" title="France">France</option>
            <option value="United Kingdom" title="United Kingdom">United Kingdom</option>
            <option value="United States" title="United States">United States</option>
          </select>
          <input type="submit" value="Submit">
        </form>

<?php
} else {

echo 'Well done.';

} ?>

Related posts

Leave a Reply

1 comment

  1. You don’t have a name="..." on your select, so nothing will be submitted there. The value of the selected option is what’s submited, so you’d need:

    <select name="country">
       <option value="United Kingdom" />UK
       ...
    </select>
    

    and

    if(isset($_POST['country']) && ($_POST['country'] == 'United Kingdom')) {
        ...
    }