Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP setcookie problem.

  • 20-05-2006 6:12pm
    #1
    Registered Users, Registered Users 2 Posts: 689 ✭✭✭


    Hi

    I'm trying to save a variable onto the users machine using PHP and cookies.

    When I use something like below...

    $visitcount=$_cookie["visits"];
    if ($visitcount == "") $visitcount=0;
    else $visitcount++;

    setcookie("visits",$visitcount)
    echo "Visit number $visitcount"

    This works in that each time the page is refreshed the visitcount goes up.... the problem is that if I then open the page in another browser window the visitcount starts at the beginning again and I have two seperate variables in each browser window...

    How can I save variable information to the users computer in such a way as it will be available to all browser windows?

    Cheers
    Joe


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    When you don't specify a expiry time for a cookie, it's known as a session cookie. This means that the cookie is only valid for as long as that browser window is open. Once you open a new browser window, it's a new session and therefore a new cookie.

    Technically there's no way to make a cookie "permanent". Though most places keep cookies alive for a year or two. Just call
    setcookie("visits", $visitcount, mktime() + (60*60*24*365))
    and it will set a cookie that sits on the machine for a year (or until they clear their cookie cache).


  • Registered Users, Registered Users 2 Posts: 689 ✭✭✭JoeB-


    thank you seamus, problem solved.


Advertisement