title: Notice: Undefined variable: captcha in C:\wamp\projects\ServiceAdmin\login\loginauth.php on line 11
body: <p>I am currently creating a login script for a project, yet trying to introduce a captcha has proven issues with it; of which I am not entirely certain of.</p>
  
  <p><strong>Login page:</strong></p>
  
  <p>Form:</p>
  
  <p><img src="https://i.stack.imgur.com/kmS1C.jpg" alt="enter image description here"></p>
  
  <p>Form code:</p>
  
  <pre><code>    &lt;div class="col-lg-8"&gt;
      &lt;script src="https://www.google.com/recaptcha/api.js"&gt;&lt;/script&gt;
        &lt;form class="form-signin" method="post" action="loginauth.php"&gt;
          &lt;h2 class="form-signin-heading"&gt;Sign in to ServiceAdmin&lt;/h2&gt;&lt;br&gt;
          &lt;label class="sr-only"&gt;Email address&lt;/label&gt;
          &lt;input name="email" type="email" class="form-control" placeholder="Email address" required autofocus&gt;
          &lt;label class="sr-only"&gt;Password&lt;/label&gt;
          &lt;input name="password" type="password" class="form-control" placeholder="Password" required&gt;&lt;br&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-4"&gt;
          &lt;div class="g-recaptcha" style="margin-top: 115px; margin-left: 20px;" data-sitekey="REDACTED"&gt;&lt;/div&gt;
  
          &lt;?php if($_SESSION['login.captcha']){
              echo '&lt;font color="red"&gt;&lt;p style="margin-left:27px;"&gt;Please tick this checkbox to verify your security.&lt;/p&gt;&lt;/font&gt;';
              unset($_SESSION['login.captcha']);
            } else {
              echo '&lt;p style="margin-left:27px;"&gt;Please tick this checkbox to verify your security.&lt;/p&gt;';
            } ?&gt;
  
          &lt;/div&gt;&lt;br&gt;&lt;br&gt;
          &lt;input class="btn btn-lg btn-primary btn-block" type="submit" value="Sign in"&gt;
        &lt;/form&gt;
  </code></pre>
  
  <p><strong>Login backend code (loginauth.php):</strong></p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  $email = $password = $captcha = NULL;
  if(isset($_POST['email'])){
    $email = $_POST['email'];
  }
  if(isset($_POST['password'])){
    $password = $_POST['password'];
  }
  if(isset($_POST['g-recaptcha-response'])){
    $captcha = $_POST['g-recaptcha-response'];
  }
  if(!$captcha){
    echo "captcha error";
    exit;
  }
  
  $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=REDACTED&amp;response=".$captcha."&amp;remoteip=".$_SERVER['REMOTE_ADDR']);
  if($response.success==false){
    "captcha error bot";
  } else {
    "success";
  }
  ?&gt;
  </code></pre>
  
  <p>No matter what, despite the captcha being filled in, it will not be recognized as entered, and will come up with error as such:</p>
  
  <pre><code>( ! ) Notice: Undefined variable: captcha in C:\wamp\projects\ServiceAdmin\login\loginauth.php on line 11
  </code></pre>
  
  <p>If anybody has any ideas as to the cause of this issue, help would be appreciated profusely.</p>