Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: User Profiles

  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Thanked 0 Times in 0 Posts

    User Profiles


    I have a script that allows users to register and login, I can also display a userlist showing whatever details (name, sex, location etc). However after that i'm stuck, how do I go about using that information so a user can have their own profile, or give them permission to do certain tasks (post a comment to an article etc). Right now I could have a database full of users but who are unable to do anything.

    Sorry that's rather vague but everywhere I google etc gives you great tutorials on how to have a register/login script but ends there. What's the point if I can't use it?

    Really all I want is for each user to have a profile, which they can edit. That'd be a start. Ideally after that i'd want them to be allowed to post comments, submit content of their own (that would need to be approved first) etc.


  • #2
    Regular Coder
    Join Date
    Mar 2005
    Thanked 1 Time in 1 Post
    well, it sounds like you have a rough start. what you are asking for is multi-step coding. You first need to code what you want them to have access to, like create a blog, or newsletter, or comment section. Then you need a form that shows up if they have access granted. Look into php sessions then you need to have an IF statement that says if they have access (i.e. if a certain field in the database is available like where the field access=granted) then start the session. Then you will need to have an if statement that says, if isset($_SESSION('sessionName') then allow them access to a form to post the comment or newsletter or whatever.

    I know its a lot, but hope it gives you a start

  • #3
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Thanked 18 Times in 18 Posts
    If you want each user to have a profile, make a table in your database called `profiles` or something and enter all the fields you want them to be able to use (favorite bands, favorite movies, where they live, how old they are, etc.). In the `profiles` table, have a field called `user_id` or something that ties to the user's id number in your login table. Make that `user_id` the primary key, since each user only needs one profile.

    Then, make a profile.php page. Use a $_GET variable or something to pass along which user_id you want to look up a profile for. Then, in the mysql_query for the profile.php page, use the user_id to get that user's profile information from the `profiles` table and print out that info however you want.

    As for permissions to allow for the users to comment or whatever, you could put that in with the username and such in the login table. You could create a field called `allow_comment_posting` that is a tinyint(1), and if it equals a 1, allow the user to post a comment.

    Definitely use $_SESSION variables to store the user's username and user_id. This will make it much easier to access them throughout your site. You can also store the permissions the user has in the $_SESSION variables.

    Hope this helps!


    Posting Permissions

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