Stuck on last chapter of basic book

Stuck on last chapter of basic book
0

#1

I am reading the book php for the web a visual quickstart guide by larry ulman, its a good book for anyone who wants to learn the basics of php mysql, im stuck on a particular thing irking me in chapter 13:

instead of copy/paste i will reference the github of this chapter:
https://github.com/LarryUllman/phpvqs-5ed/tree/master/13/htdocs

he has a function isadministrator() in an includes file which checks for the existance of a certain cookie, yet in his footer he has exceptions in his logic for the login and logout page, his reasoning that isadministrator will work on every page except those two.

can someone please go over with me why its not working on these two pages:
on login.php : basically when the pass and user is correct the server sends a cookie to the client but its not available to be read right away unless you refresh the page?

on logout,php:
destroys the cookie by setting it to false and its time in the past…
so then why wouldnt isadministrator work? why does the browser still think the cookie exists? is this the same reason as on login.php page?

the other thing im trying to fully understand is why this script will not come back with the error of headers already sent, im guessing because in his footer hes not trying to set or destroy any cookies, and he already sends or destroys these cookies at the top of his scripts on login and logout?

in that case how come the header file hes including doesnt cause headers already sent error because if you look at this file he is sending this header includes to the client first

edit: (correction) upon reviewing his scripts i do see that on login.php and logout.php he does indeed do all his cookie modifications before including the headers…where on the other pages this is not the case so i guess thats ok…


#2

Guys i found the answer to this question relates to how cookies are read and sent, basically the way i understand it is you will have the cookie on the client side on login, however you cant access it unless you refresh the page or on the second visit to the page, and similarly on Logout, that although you destroyed the cookie by setting it with a retroactively false cookie, you will not know about it right away from the client side.

It occurs to me that this is related to the way php itself works that its not like jscript that is processed on wherever your browser physically, but on the location of the server itself, is why you need things like xampp to run it from your side it needs its own special processor.

I found on stacked a solution if you wish to have the value of a cookie immediately, if anyone is interested in discussing this, reply to this thread.

Someone can correct me if im wrong, but I did not find anything in the fcc documentation explaining this concept, so please advise if we need to add it to the tutorials