title: How to keep variable constant even after page refresh in PHP
body: <p>I'm making a simple hangman application and I have my php file and a separate .txt file holding the words, one on each line.</p>
  
  <p>What I want is for the $word variable to remain constant even after the page refreshes since I was planning on using a GET or POST to get the user's input.</p>
  
  <p>In the example code below I want $word to stay the same after the form is submitted.
  I believe it's a simple matter of moving code to another place but I can't figure out where any help for this PHP noob would be appreciated!</p>
  
  <p><strong>wordsEn1.txt:</strong></p>
  
  <pre><code>cat
  dog
  </code></pre>
  
  <p><strong>functions.php:</strong></p>
  
  <pre><code>&lt;?php
  
  function choose_word($words) {
      return trim($words[array_rand($words)]);
  }
  ?&gt;
  </code></pre>
  
  <p><strong>hangman.php:</strong></p>
  
  <pre><code>&lt;?php
  include('functions.php');
  
  $handle = fopen('wordsEn1.txt', 'r');
  $words = array();
  
  while(!feof($handle)) {
  $words[] = trim(fgets($handle));
  }
  
  $word = choose_word($words);
  
  echo($word);
  echo('&lt;form&gt;&lt;input type="text" name="guess"&gt;&lt;/form&gt;');
  ?&gt;
  </code></pre>