title: How do I implement Google Authentication for my website?
body: <p>I've been trying to implement Google Authentication for my website for the longest time now, but programming really isn't my strongest suit. Below is my coding, and I would really appreciate if someone would please point out why it isn't working properly. At the moment, I am able to dynamically create a QR Code that can be scanned with the Google Authentication application, which would produce the one-time code. However, the issue is, when I key in the code, it will always say that I'm wrong, regardless of whether or not I keyed in the right code. Please be patient with me, as I said, I'm not really good with PHP. </p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  require 'GoogleAuthenticator.php';
  
  $ga = new PHPGangsta_GoogleAuthenticator();
  
  $secret = $ga-&gt;createSecret();
  echo 'Secret:'.$secret; //echo-ed the secret so it would be easier for you guys
  
  $qrCodeUrl = $ga-&gt;getQRCodeGoogleUrl('Three Musketeers', $secret);
  
  $oneCode = $ga-&gt;getCode($secret);
  echo 'One-Code:'.$oneCode; //echo-ed the oneCode so you guys wouldn't need to scan the QR Code everytime
  $_SESSION['oneCode'] = $oneCode; 
  
  ?&gt;
  
  &lt;br&gt;
  &lt;br&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHP Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;img src="&lt;?php echo ''.$qrCodeUrl;?&gt;" /&gt;
  
  &lt;form action="2fa.php" method="POST"&gt;
  Code: &lt;input type="text" name="code" maxlength="6"&gt;&lt;br&gt;
  &lt;input type="submit" name="submit" value="submit"&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  if(isset($_POST['submit']))
  {   
  
      $code = $_POST["code"];
      if (empty($_POST['code']))
      {
      echo "&lt;script&gt;alert('EMPTY');&lt;/script&gt;";
      }
      else
      {
            if ($code == $_SESSION['oneCode']) //I tried just putting $code == $oneCode, but it doesn't work as well. However, you guys may feel free to try anyway
            {
                 echo "&lt;script&gt;alert('CORRECT');&lt;/script&gt;";
            } 
            else
            {
                 echo "&lt;script&gt;alert('WRONG');&lt;/script&gt;";
            }
      }
  }
  
  ?&gt;
  
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>