Location of login using OO PHP

Posted on 2012-09-16
Last Modified: 2012-09-16
Hi All,
This is probably a pretty simple question but I'm just wondering about structure of a php script.  I'm writing a user login system using object oriented php.  I've seen a couple of examples online where they have a simple system for users to login.  My question is that some of the examples have the login section in a user class while some have it in a session class.  Which one would be preferrable?  I'd also like to have a guest access as well.  My session information is stored in a MySQL database.  Like I said the whole thing is pretty simple so I don't think I need any ready built code, plus I'd like to learn the stuff myself.  Thanks in advance.
P.S. I didn't include any code since this is more of an organizational question, but if anyone wants to see what I'm going off of just let me know and I'll copy it in.
Question by:William-B
    LVL 82

    Expert Comment

    by:Dave Baldwin
    It doesn't matter all that much where the login page is.  It is more important to realize the code that checks the login has to run on every page that is supposed to be protected by the login.  You would want to make that part pretty simple and direct so it is essentially invisible to the rest of the page.
    LVL 107

    Assisted Solution

    by:Ray Paseur

    Author Comment

    Thanks for your responses.  I guess I may not be understanding the answers you gave.  I was wondering which class should handle the login procedure, the Session class or the user class.  I might just be having an obtuse day, so please let me know if that's the case.  Thanks again.
    LVL 82

    Accepted Solution

    We're not exactly answering your question because where you put the login isn't that important.  What is really important is checking the login status on every page that is 'protected' by the login.  That code needs to be at the beginning of every single page that is to be protected.

    Author Closing Comment

    Thanks for your help guys.  Points all around.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now