cookies with php

A

Anonymous

Guest
okay when someone trys to download a file from my page i want to search for a certain cookie. if the cookie is not there i dont want them to download the file and i want to display a message. if the cookie is there i want them to be able to download the file.
so if someone could help me with this coding it would be greatly appreciated
 
Have you tried using session registers?

Code:
At the top of your php script:
session_register("userid");

Now userid is $userid and will be stored temporarily in your machine, with a cookie on the users computer being used as a key. If the user closes his/her browser or doesn't go on your site for 5 minutes (by default) then the cookie will no longer work. You can change the settings for cookie timeouts although I never had a need to so I'm no expert on that.

You can use this in conjunction with a login screen / user info in a database for many different types of site designs. I've used logins for almost all of my websites with cookies as the basis of them. Useful stuff.
 
Forgot to mention (although it should be obvious) : It's called the session register because that variable sticks around for as long as the session is active. This is a good way to keep the same value on multiple scripts (with only a specific user having access to them).
 
i dont want ppl to have to login tho i just want a way to tell if they have visited the site and if they haven't then they cant download
 
Back
Top