davo Posted August 17, 2014 Share Posted August 17, 2014 I'm trying to drop a cookie when a page is viewed when the user is not logged. I've tried using Isloggedin {}else{do this} but that didn't work. It just kept on dropping the cookies regardless. So I also tried if ($user->isGuest())... but that doesn't seem to work either.. it just keeps on with the cookie. Maybe I'm using it wrong? <?php $this_page = $page->id; if ($user->isGuest()) { setcookie(date("Y-m-d"), $this_page, time() + 500); if (IsSet($_COOKIE['pageid'])) { $cookiepageid = $_COOKIE['pageid']; } } Link to comment Share on other sites More sharing options...
adrian Posted August 17, 2014 Share Posted August 17, 2014 Well the first thing is to make sure that isGuest() is working, so do something simply inside it like: echo "true". When you used isLoggedin() did you get the case correct? Then if that works you know it's an issue with your cookie code. It seems strange to me to use a date format as the cookie name and then isset for a cookie named "pageid". Is that all intentional? Link to comment Share on other sites More sharing options...
davo Posted August 17, 2014 Author Share Posted August 17, 2014 I think I was getting pickled looking for the cookie when I actually WAS a guest! A little bit of clear thinking helped. I think it's doing it's job correctly. And yes, I'd also forgotten to change the isset variable. Next job will be to start collecting the cookies ready to add to the audit when the user is next logged in. <?php $this_page = $page->id; if ($user->isGuest()) { $youloggedin = "you a guest"; } else { $youloggedin = "you not a guest";} $today = date("Y-m-d"); if ($user->isGuest()) { setcookie($today, $this_page, time() + 500); if (IsSet($_COOKIE[$today])) { $cookiepageid = $_COOKIE['pageid']; } } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now