As I stated in my comment, from your description (although rather vague and not very clear), I think the problem may be that you are trying to read a cookie before sending it to the server.
The way cookies work is as follows:
- You make a request
- SENDS server server cookie back to client
- Page loading - A cookie is NOT visible to PHP on this page.
- Refresh
- SENDS client client cookie for server
- The server WILL GET a cookie header, so PHP can read it
- Page loading - Cookie IS is displayed here.
If you have not tried it, please upgrade again!
Since you want to read it at the same time as setting, just save the value you set and use it. Alternatively (although this has not been verified), you can manually set it in the $_COOKIE .
So something like this:
setcookie("helloworld", .. ); $_COOKIE['helloworld'] = $value;
Then you can read it normally. Please note that I would not recommend overriding the value of the automatic superglobal (the same applies to $_REQUEST , $_POST , $_GET , etc.), and instead prompts you to just save the value you set, and use this.
Another approach would be to use a “gateway” form, meaning that you set a cookie on the gateway page, which then continues to redirect to the next page.
For example, let's say that your stream was as follows: login.php → account.php . Instead of POST'ing your login form directly to account.php , you have 2 options.
Option 1: POST back to login.php, configure the cookie, and then redirect to account.php . Option 2: you have a gateway, for example logincheck.php , POST, set a cookie, and then redirect to account.php .
This way account.php can always see your cookie.