title: PHP Keep the variable scope even after the page reload
body: <p>The website generates the random number from 1 to 100 when accessing the <strong>first page</strong>(page1.php). And the user will guess the number.</p>
  
  <p>The first page contains
   - a text box for accepting a
     number from the user, and a submit button.</p>
  
  <p>The <strong>second page</strong>(page2.php) will be returned to the user if the guess number is too high or too low. And the page shows a message telling the user "Too High" or "Too Low". The page also contains
  a button(retry button) that allows the user to go back to the first page(page1.php) to re-enter a new number
  a button that allows the user to quit the game.</p>
  
  <p>The <strong>third page</strong>(page3.php) is returned to the user if the guess is correct. The page displays "Correct", the random number, and the count of tries.</p>
  
  <p>And I have this index.php which is heart for all the pages. And here is the code.</p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>    &lt;?php
  
  $name = '';
  $inputnumber = '';
  $random = 33; //this is just an assumption to keep it simple
  $message = '';
  $guesscount = '';
  if (isset($_POST['action'])) {
      $action = $_POST['action'];
  }
  
  if ($action === 'guess') {
      $guesscount = $_POST['$guesscount'];
      $inputnumber = $_POST['$inputnumber'];
      if ($inputnumber == $random) {
          $message = "Correct!";
          include 'page3.php';
      }
      if ($inputnumber &gt; $random) {
          $message = "Too High";
          include 'page2.php';
      }
      if ($inputnumber &lt; $random) {
          $message = "Too Low";
          include 'page2.php';
      }
  }
  
  if ($action === 'retry') {
      include 'page1.php';
  }
  </code></pre>
  
  <p><strong>page1.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Number Guess&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Number Guess&lt;/h1&gt;
          &lt;form name="myForm" action="index.php" method="post" &gt;
              Number Guess: &lt;input type="text" name="$inputnumber" value="&lt;?php if(isset($inputnumber)==1){
  echo $inputnumber;}else echo ""; ?&gt;" /&gt;&lt;br&gt;
  
              &lt;input type="submit" name="action" value="guess" /&gt;
              &lt;hr&gt;
              Guess Count: &lt;?php echo $guesscount; ?&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>page2.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Number Guess&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Number Guess&lt;/h1&gt;
          &lt;form name="myForm" action="index.php" method="post" &gt;
              Message: &lt;?php echo $message; ?&gt;
              &lt;input type="hidden" name="$guesscount" value="&lt;?php echo $guesscount;?&gt;"/&gt;&lt;br&gt;
             &lt;input type="submit" name="action" value="retry" /&gt;
  
              &lt;hr&gt;
             Guess Count: &lt;?php echo $guesscount;?&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>page3.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;Number Guess&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;Number Guess&lt;/h1&gt;
          &lt;form name="myForm" action="index.php" method="post" &gt;
              Message: &lt;?php echo $message; ?&gt;
              Number of Tries: &lt;?php echo $guesscount; ?&gt;
             &lt;input type="submit" name="action" value="ok" /&gt;
  
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>page1.php is the page to load first. </p>
  
  <p>Challenge I have faced is, I couldn't keep the $guesscount stable always. It keeps resetting on me. I have tried session but couldn't resolve it.Please help resolving it.
  Thanks in advance.</p>