SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking help on getting ideas around first class

    Ok, I want to do classes, my work is getting to big and I am rewriting too much code.

    So I got the Wrox professional php book and went through it...I also have been looking at everything I can get my hands on online.

    So the first project is to do a class for login and authentication management. I searched the forums and found a couple of previous posts and there was one thing I did not get.

    In my class I am thinking I should have the following functions:
    adduser - insert a new user
    reset_passwd - ummm...reset a users password
    login
    logout
    edit_info - for updating info like email
    is_logged_in
    check_permissions - return true if they have a certain permission
    login_form - to echo the login form to make it easy to include on multiple pages

    All of this leads me to a couple questions...
    where does a constructor fit into this?
    Is a constructor really required?
    Does this really fit as a class, or just a group of functions?

    While I have done some C++ work in classes and some Java, I have not tried to fit classes to php where it seems to be more procedural.

    Can anyone help clear this up a bit for me. I would appreciate it.

    Thanks
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  2. #2
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where does a constructor fit into this?
    That depends, do you think you will need a constructor?

    [class]Is a constructor really required?[/class]

    Not always. But if you need anything setting automatically on class invocation then a constructor is best.

    Does this really fit as a class, or just a group of functions?
    If you use it in combination with a session class then I'd say yes....

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry if I seemed to missed the boat. I do intend to try to use sessions to store the login information. I would use the login function to retreive their user info from the db after the login form.

    So what is the Session class and how would that change my current plans?

    Thanks for bearing with me.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I really prefer objects as the code looks cleaner (IMO) and can be more easily updated. Of course this depends on whether using a class is relevant or not.

    With PHP >4.2, the $_SESSION super-global is accessable in objects so using sessions with a User Administration class is a lot easier. Phil, maybe you could elaborate on "session class"?

  5. #5
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wasn't thinking of any specific code, but an authentication class should do nothing but handle authentication, it shouldn't have anything to do with session. Likewise a session class shouldn't have anything to do with authentication. So an auth class is best when used in combination with other classes to provide the rest of the applications functions.....

  6. #6
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, so what I would do then would be to pass a username and password from a $_POST to the login function. Then I would call a function in a session class that would register the session vars (assuming the login is correct).

    I still don't see how to involve the constructor. I think I am missing how to do this in a class like way. I don't see how after the user posts the username and login to involve a class. It seems I would just call the login function. Which would, in turn, just call a session_register function.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  7. #7
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you can't think of any use for a constructor then don't use one. Its not mandatory.

  8. #8
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks for the help.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  9. #9
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I'm curious as to why you would use a seperate object to handle sessions...

  10. #10
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    I'm curious as to why you would use a seperate object to handle sessions...
    Becuase classes should only do very specific tasks.

    Sessions are not neccesarily the only way to maintain authentication.

  11. #11
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Yes classes should only do very specific tasks but I don't see the need for an object to control sessions, I would just obviously do it a different way to you...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •