Cookie not available to browser immediately on page load.

+1 OLayemii Garuba · August 27, 2015
Am creating a site and am using a db so what i did was fetch the user name from the database store it in a cookie and print it out on the first page after login.
But if i close my browser and go to the site main page directly fro local host the username doesn't print anything firstly till i reload the page a second time..any ideas on this? i tried checking if the cookie isset and reloading the page till it is set but it still doent work.

Post a Reply


Oldest  Newest  Rating
0 OLayemii Garuba · August 28, 2015
sessions don't need a second refresh before being available to the browser right? I created a cookie for long term login since sessions are destroyed on browser close . am also using sessions.. my code would store just the user id in the cookie so after a user login it queries the database based on the id in the cookie then transfers the result into sessions... so you see cookie still gets to be the bedrock and its not being available to the browser immediately
0 Marco Schindler · August 28, 2015
You should consider using sessions if you're building a login with PHP.

You can then store the username in a session variable like that

$_SESSION['username'] = 'Your Data';

Here's a link to some session basics.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.