stopping variables from resetting on self call
<p>In the following PHP code, I'm trying to generate a random number if its not already and store it in a variable called <code>$number</code>, also I'm taking user input and storing it in <code>$userInput</code>.</p>

<p>Every time the submit button is pressed , the same page is called again using <code>$_SERVER['PHP_SELF']</code>.</p>

<p>My problem is that I want the <code>$number</code> to keep its value once its set. no matter how many times the submit button is pressed, which is something that is not happening now.
the <code>$number</code> is set every time I press submit button.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;title&gt;Number Guessing Game!&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?php 
            $userInput = $_POST['number'];
            if(!$number){
                 $number = rand(1, 500);
            }
            else{
                 echo "random number is $number &lt;br&gt;";
                 echo "you entered $userInput";
            }

            echo "&lt;h3&gt; $number &lt;/h3&gt;"; //just to see if the number is changing everytime
       ?&gt;
       &lt;form method="post" action="&lt;?php echo $_SERVER["PHP_SELF"];?&gt;"&gt;
            &lt;input type="text" name="number" /&gt; &lt;input type="submit" name="Submit"
            value="Submit" /&gt;
       &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
