PHP cannot read cookie from same page
<p>Hey guys i created a simple PHP page to  set a cookie and after reloading  check if the cookie is existing and echo out its content.</p>

<p>Setting the cookie works. Reloading works. Displaying the cookie works.
BUT: If I leave the page (go to another url etc.) and come back again, the page can NOT read the cookie which was set before, although the cookie hasn't expired and firefox says it's still existing.</p>

<p>Code of the php file:</p>

<pre><code>&lt;!DOCTYPE html&gt;

&lt;html&gt;
&lt;title&gt;Authentication cookie&lt;/title&gt;
&lt;body&gt;

&lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt;

Authentication code: &lt;input type="text" name="authcode" value="&lt;?php echo $_GET["authcode"]; ?&gt;"&gt;
&lt;input type="submit" name="submit" value="Submit"&gt;
&lt;/form&gt;&lt;br&gt;



&lt;?php
$cookie_name = "authpi";
$cookie_value = $_POST["authcode"];
setcookie($cookie_name, $cookie_value, time() + (10 * 365 * 24 * 60 * 60), '/', '10.0.0.2'); // 86400 = 1 day

 ?&gt;


&lt;?php
if(!isset($_COOKIE["authpi"])) {
     echo "Authentication Cookie named '" . $cookie_name . "' is not set!";
        #header("Location: http://www.google.at/");
} else {
     echo "Authentication Cookie '" . $cookie_name . "' is set!&lt;br&gt;";
     echo "Your authentication code is: " . $_COOKIE[$cookie_name];
}
?&gt;

 &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; After setting the Cookie reload the page to make sure it works!&lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Thanks for your answers!</p>

<p>EDIT: Tried to explain my problem better.</p>