Since userId's are specific to a logged in user and not a specific computer, a cookie does not seem like the way to go. Basic authentication in PHP is usually done with sessions, so you could just as well add the userId to the session.If the session times are too short, increase the session time.