June 14, 201115 yr Well, for my latest system I want to store the login sessions in the database. What would be the best way to go about storing/reading sessions in a database? And how would I actually do this? I currently have a "user" class and within there I will hold all my functions, I'm guessing I'll want to do something like this: on login - set $islogged to true, store session in database, with session_id and user_id __construct - check if there is a session stored within the database that is equal to their user id and session id, if so return islogged as true, else return as flase. logout - destroy main session and remove it from the database. Many thanks Edited June 14, 201115 yr by MatthehCarter
June 14, 201115 yr Author You know, that people ask for help because they want a conversation while getting help. Realms of information don't help some people, I don't learn like that, never have and never will. ANYWAY. I put my mind to it, and I've built it from session storing to reading and I've now got it working! WEWP
June 14, 201115 yr Yeah, that's fine, but people are just going to point you to tutorials anyway. People are here to help with coding issues, like code behaving oddly, not walk you through every bit of coding practice. For example, say you've been using a tutorial on how to write sessions to a database, but have got stuck with it, you then ask, and people will try and help. Showing you've at least put some effort into your problem is always a good way of ensuring people will try and help You'll never get anywhere if you need to learn by asking how to do stuff on a forum. Initiative is what you need. Be proactive, read a few tutorials on the subject (there's always plenty about almost everything). If you can read a forum post that explains how to do something, I don't see how "Realms of information" AKA a tutorial is any different. You still need to read it Also, you say you've not learnt like that, but have actually managed it? You must have gotten references from somewhere
June 15, 201115 yr You may be interested in using session_set_save_handler(). This is exactly what you need to store sessions in the database BUT beaware you may run into problems this is not a simple function to pull of and a MUST is oop.
June 15, 201115 yr Author Yeah, that's fine, but people are just going to point you to tutorials anyway. People are here to help with coding issues, like code behaving oddly, not walk you through every bit of coding practice. For example, say you've been using a tutorial on how to write sessions to a database, but have got stuck with it, you then ask, and people will try and help. Showing you've at least put some effort into your problem is always a good way of ensuring people will try and help You'll never get anywhere if you need to learn by asking how to do stuff on a forum. Initiative is what you need. Be proactive, read a few tutorials on the subject (there's always plenty about almost everything). If you can read a forum post that explains how to do something, I don't see how "Realms of information" AKA a tutorial is any different. You still need to read it Also, you say you've not learnt like that, but have actually managed it? You must have gotten references from somewhere Yes, I got the references from my brain. Thinking through the process on how I can do this, and speaking to other PHP coders. As I said, I can't learn from reading realms of text, I like to have a conversation while learning things, so if I don't understand a certain function I can always go back and ask for an explanation in simple-terms instead of having a complex explanation. Anyway, seen as though it's sorted now, no need to reply
June 18, 201115 yr Yes, I got the references from my brain. Thinking through the process on how I can do this, and speaking to other PHP coders. As I said, I can't learn from reading realms of text, I like to have a conversation while learning things, so if I don't understand a certain function I can always go back and ask for an explanation in simple-terms instead of having a complex explanation. Anyway, seen as though it's sorted now, no need to reply Mmmm if this is the case idk how fluent u are in php or how your best practices would be considering you prob would not be interested in studying the php manual
June 20, 201115 yr Author Did I say that you should tailor the replies to me specifically? No. I was simply stating that I like to be helped, how I help others. By giving them somewhere to start with and build on, a general code to use. Referring to google is not helpful. Don't you think people google before they come to forums? Seriously, people nowadays.
June 20, 201115 yr Referring to google is not helpful. Don't you think people google before they come to forums? You know I'm not after an argument, but you've just contradicted yourself. You say google isn't useful yet apparently everyone uses it before they come to the forum. The fact you don't think google is useful is proof enough you can't use it. I mean they webs most popular search engine and site for that matter by chance. Google is without doubt the best resource on the web, and to think its useless is very naive Fact of the matter is that the vast majority of people who ask questions on forums are too lazy to get off their arses and look through search engine results for themselves. Before you start off on a rant about how you arent and that you've looked, I'm not referring to you specifically. I answer questions for people on a few websites, and over the last few years have racked up a good 20,000 forum posts. The one thing that's been pretty common is people too lazy to google. I mean it came to a point where LMGTFY was built, so clearly its pretty common
June 21, 201115 yr Well, for my latest system I want to store the login sessions in the database. What would be the best way to go about storing/reading sessions in a database? And how would I actually do this? I currently have a "user" class and within there I will hold all my functions, I'm guessing I'll want to do something like this: on login - set $islogged to true, store session in database, with session_id and user_id __construct - check if there is a session stored within the database that is equal to their user id and session id, if so return islogged as true, else return as flase. logout - destroy main session and remove it from the database. Many thanks You seem fairly savvy at PHP given you're using OOP and looking to build a fairly comprehensive system here. i.e. storing sessions in the DB to stop spoofing etc. I guess you're looking for some logic before you commit to building out the method. Here's my .02. Modify your login method to do exactly what you said, store a session_id(MD5 or SHA1) and a user_id. In each member view match the session_id in the DB with the actual session_id (MD5 or SHA1). If all okie continue as normal, else bounce their sorry ass for trying to spoof you. You may want to add an additional "privelage" field in the DB whilst at it, this way you can use permission levels if required. If($userLoggedIn && $userLevel === 5) Sort of thing. I'm not the greatest of coders but hopefully that will help on top of the tutorials listed.
Create an account or sign in to comment