I added the path but it still doesn't change the fact that I can log in, but if I go back to the url 2 seconds afterwards it forces me to log in again.
You haven't actually set the cookie just by doing that. You've created a cookie but then not sent it to the browser. You need to print the header and explicitly tell it to include the cookie.