Page Protect page using a PHP script

I basically copied the PHP script below to protect a page from another post I found on this forum, and made a few changes. It works fine for the login but I have to reenter the credentials every time I go back to this protected page. It looks like the script is setting a cookie with no timeout to use on second visit etc… I would like the user to enter the credentials once and for revisits to the page use the setcookie to validate the user.

Any of you that know PHP script see what I am missing or in error in the script?

Or is there a better way to do this with Blocs 3? (1.5 KB)

You have skills @eagle. It would be great if one of the Blocs experts could make this work.

I have made a little progress. No cookies are being set, for some reason I don’t see any cookies, I opened Safari Develop menu, the Web Inspector and then clicking on storage tab, I don’t see any cookies. So, for some reason the setcookie does not produce the results I was expecting…

Any ideas why this might be happening?

Update… I found this:

It says " This requires that you place calls to this function prior to any output, including html and head tags as well as any whitespace.

Does any one know how to meet this requirement in Blocs 3? How can you set the cookie prior to get a valid Login/password??? Seems like a catch 22 for trying to do what I want…