Jump to content

Login and Membership Structure


BenMo

Recommended Posts

Hello, I'm a PHP beginner, and I'm trying to build a simple site that has basic login functions, such as allowing them to sign up by entering their email and password, and then logging in and have the site display their account's data on various pages.

 

I've created pages that allow them to create an account and login and log out of the account, but I'm not sure how to go about the structure of creating a collection of pages where information about the account is accessible at all times.  For example, on a given page I'd like to be able to pull out whether or not they are logged in, and if they are, display their name on the page.  The only strategies I've used so far are $_POST and some forms; is this all I need?

 

Where can I find some good tutorials on how to pass data around in between pages in this manner?  Or any general framework help would be great.  Thanks so much!

Link to comment
Share on other sites

you'd be looking at storing the username and / or user id in the $_SESSION array just after the login has been confirmed to be valid. a call to session_start() at the top of each of your pages will make this info available.

 

<?php
session_start();

if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0)
{
   echo 'Hello ' . $_SESSION['user_name'] . '!';
}
?>

 

obviously a lame example, but it should give you an idea to get started.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.