php - Cookie not saving -


on site user greeted yes/no menu determines whether see it, peiece of code.

if(!isset($_cookie['banguser'])) {             // createrandomid() method , return unique id user             $unique = '';             // setting cookie, name = banguser, cookie expire after 30 days             setcookie("banguser", $unique, time() + (60*60*24*30));             $data['firsttime'] = true;         } else {             $data['notfirsttime'] = true;         } 

if user clicks yes run

function createcookie() {         // function gets called when user clicks yes on firsttime menu.         // purpose of function create cookie user.         // first we'll give them unique id         $unique = $this->createrandomid();         // set expiration time         $expireat = time() + (60*60*24*30);         // unique id available can set our cookie doing same function before         $_cookie[] = setcookie("banguser", $unique, $expireat);         // cookie set can 100% check, check cookie set , if redirect         // homepage         if(isset($_cookie['banguser'])) {             // need save cookie data database             // first let's load model cookies             $this->load->model('cookiemodel');             $this->cookiemodel->savecookierecord($unique, $expireat);             redirect('/welcome');         }     } 

if no code run,

 function createcookielater() {             // function gets called when user clicks yes on firsttime menu.             // of function create cookie user, time it,             // expire when user closes window.             // again give them id             $unique = $this->createrandomid();             $_cookie[] = setcookie("banguser", $unique, 0);             // have set cookie, again need check set,             // , if can redirect user main page, again.             if(isset($_cookie['banguser'])) {                 // need save cookie data database                 // first let's load model cookies                 $this->load->model('cookiemodel');                 $this->cookiemodel->savecookierecord($unique, $expireat);                 redirect('/welcome');             }         }  

hope can me

you should specify domain when storing cookies:

setcookie("banguser", $unique, time() + (60*60*24*30)); 

should become:

setcookie("banguser", $unique, time() + (60*60*24*30), '/', '.yourdomain.com'); 

i'm pretty sure issue.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -