RoninStretch Posted April 26, 2007 Share Posted April 26, 2007 Hey all, First post so be nice. Here is my set up at the moment: I have a simple site where you can create a user, login and see an info page that displays your acocunt info. Problem is I need a way to keep the user logged in. So that when he surfs to another page.. IE the account info page, he see his information being displayed.. The creation process adds a row to a Table in a mysql database. Each user gets a unique ID number along with several other fields. So the script i'm trying to make would know what ID the current user is and grab the appropriate data from the correct row of the table. So i need to do something when the login is processed to record in the clients browser cache (or cookies or????) that he is logged in. Then each page would check to see if he is logged in and if so record his ID number in a variable? Am i on the right lines? I've been looking around but the informations always just not quite what I need. Any help appreciated - Stretch Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/ Share on other sites More sharing options...
pocobueno1388 Posted April 26, 2007 Share Posted April 26, 2007 When they log in you need to register their ID number as a session, then you can check if that session exists on each page, and if it doesn't they are not logged in. Not sure if that is going to fully answer your question or not... Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238744 Share on other sites More sharing options...
RoninStretch Posted April 26, 2007 Author Share Posted April 26, 2007 it might do when i go look up a session.. thanks for the reply.. Im coming from a basic C++ background so it's just learning the functions etc. Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238745 Share on other sites More sharing options...
pocobueno1388 Posted April 26, 2007 Share Posted April 26, 2007 Yeah, there are lots of good tutorials on sessions and exactly how to use them when working with a login ... so I don't think you will have a problem finding one. If you do for some reason, I will find them for you, just post back on this thread and I will see it, or someone else will =] Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238753 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 If your new to the scene, the easiest thing you could do is cookies. Cookies can keep people logged in. Usually its best to store the users id and an md5 password in cookies to be safe, but do whatever youd like, this is merely an example. $logged = mysql_fetch_array(mysql_query("SELECT * FROM usernames WHERE username = '".$_COOKIE['user']."' AND password = '".$_COOKIE['pass']."'")); Then if a page should be only for logged in users, put this around it.. IF($logged[id]){ } else { // you gotta be logged in. } Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238757 Share on other sites More sharing options...
RoninStretch Posted April 26, 2007 Author Share Posted April 26, 2007 hmm well i think sessions will work for now. i've started looking into them already I can start a session and get the user's id in a session variable. What i can't seem to find is how to load a session variable in a different php file. And how to forcibly end a session.. i.e Logout. thanks again. Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238767 Share on other sites More sharing options...
sw0o0sh Posted April 26, 2007 Share Posted April 26, 2007 session_destroy(), session_unregister() read about em on php.net Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-238770 Share on other sites More sharing options...
RoninStretch Posted April 26, 2007 Author Share Posted April 26, 2007 Thanks for that, i've read up all on sessions now and i'm looking at cookies. I think understand what you posted above. So a good way to handle login is to take the Username and Pass, store them in a cookie. Then every page checks the cookie against the db and if it's right gives logged in status and if wrong can error msg. Seems to make sense...If not please tell me Link to comment https://forums.phpfreaks.com/topic/48719-help-for-php-noob-please/#findComment-239229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.