Hi, I would like to use cookies to manage users information on my site. I want that every time a a visitor comes my website my site check if he has a cookie from the last visit. If Yes to grab information about this visitor from my DB. If No to setup a cookie and store some info on the DB (for next visit). During the visit to add/change stuff on the DB. If the user doesn't allow cookies he/she has an option to sign in/register and once they type their user and password they are logged in and the users code is stored at the session level for the next pages. If you are femiliure with ASP you know that usually this is done inicialy at the global.asa and than the information is stored at the session level for the rest of the visit. How should i do this with PHP? I thought about putting the php code that handles cookie and users DB on each page on my site. This means the cookies will be read a few times each visit. I'm not sure this is the way to go and this also doesn't solve me the users that doesn't allow cookies senario. This doesn't solve the user
Hi, I would put all the cookie and session things in one file, and just include that in your pages that you want to restrict access to. i have one file that has the session stuff for members. It basically has the session_start(), then checks if the session exists session_start(); if(!isset($_SESSION['name'] { go to log in page.} else{ decrypts the session name; checks the session info to make sure it is valid; looks up the member info in the database; assigns variables for user name, email, etc...what ever you have stored in the database; } I just include this file at the top of each one of my member pages, and it seems to work pretty well. I have not used cookies and sessions together, so I am not sure if you can put some cookie functions in there as well, and on the first login, if the person accepts cookies, one will be stored, and if they don't a session is in place. If they have the cookie, they do not have to login on the next visit, but if they do not accept cookies, they will have to login again to set the session. Michael
I built a procedure that does what i need: It's a php file in my site that once i view it with my browser it checks to see if i have a specific cookie, and if so it adds 1 to the field 'visits' in a database as my visits counter. If the cookie doesn't exists a new row in the users database table opens and the cookie is set for the next visit - the cookie value is the ID of the new row. This should happen only on the first page the visitor see, the rest of the visit i need to work with information on a session level. So the code i wrote first checks if a session variable is set: session_start(); if(isset($_SESSION['userCookie']))...... I use this session variable to pass the user ID from page to page to collect and retrive information from the DB. (i don't want to do it also with cookies because not all visitors allow them) My problem is this: The php file i created works fine - it does exactly what i need. The problem is when i include it in pages of my site like this: <? include 'user-manage.php'?> The session information doesn't pass from one page to another. so every page view seems like a view visitor. I hope this wasn't too long... and someone can help me.. i'm a little stuck! Thanks.