Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    In this tutorial you will learn how to create a basic member system. The script will be able to sign members in and out.

    Here is a list of the files and what they do

    File: index.php Purpose: Checks if a member is logged in. If not, displays the login form. If so, displays a welcome message.
    File: login.php Purpose: Logs the member in, takes the username and password and compares them against a database tables rows.
    File: logout.php Purpose: Logs the member out, provides a link back to the index page
    File: conn.php Purpose: Connection details for your database
    File: install.php Purpose: Creates the database table used to store member details
    File: membershome.php Purpose: Where the member is redirected to when they login correctly.

    I will start with the install.php and conn.php as these are vital for the rest of the script to function.

    conn.php
    PHP Code:
    <?php
    // Edit the values of the below variables to match your database connection settings
    $location "localhost";
    $username ""// Edit
    $password ""// Edit
    $database ""// Edit

    $conn mysql_connect("$location","$username","$password");
    mysql_select_db($database,$conn) or die ("Could not open database");

    ?>
    install.php
    PHP Code:
    <?php

    include("conn.php"); // Needs a valid connection to create a database

    $query = ("CREATE TABLE `members` (
    `member_id` INT( 4 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `member_username` VARCHAR( 40 ) NOT NULL ,
    `member_password` VARCHAR( 40 ) NOT NULL ,
    `member_fullname` VARCHAR( 40 ) NOT NULL ,
    `member_age` INT( 3 ) NOT NULL ,
    `member_location` VARCHAR( 30 ) NOT NULL ,
    `member_notes` TEXT NOT NULL
    ) ENGINE = MYISAM COMMENT = 'member table for member-script for wdf tutorial';"
    );
    $res mysql_query($query) or die(mysql_error());

    if(
    $res) { echo "Table created!"; }

    ?>
    Now, we have created the table. Now we will create index.php

    index.php
    PHP Code:
    <?php session_start(); // needed to track members logged in
    header("Cache-control: private");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>

    <head>

    <title>Member System</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    </head>

    <body>

    <h1>bfsog's member system for WDF.</h1>

    <?php

    if(isset($_SESSION['username']))
        { 
    // if a member is logged in
    ?>
    Yay, <?php echo $_SESSION['username']; ?> is logged in.

    <br /><br />

    <a href="logout.php">Logout</a>

    <?php

    }
        else
            { 
    // if no member is logged, display the login form
    ?>

    <form name="login" action="login.php" method="post">

    Username: <input type="text" size="30" name="username" />

    <br /><br />

    Password: <input type="password" size="30" name="password" />

    <br /><br />

    <input type="submit" name="submit" value="Login" />

    </form>

    <?php

    }

    ?>

    </body>
    </html>
    Here is login.php, which will check the database for a match
    PHP Code:
    <?php session_start();
    header("Cache-control: private");
    include(
    "conn.php");
    function 
    cleanUp ($var)
    {
        return 
    mysql_real_escape_string($var);
    }
    $username $_POST['username'];
    $password $_POST['password'];
    $h $_POST['h'];
    $u cleanUp$username );
    $p cleanUp$password );
    $query "SELECT * FROM members WHERE member_username = '$u' AND member_password = '".md5($p)."' LIMIT 1";
    $res mysql_query($query) or die("Error!! - " mysql_error());
    if (
    mysql_num_rows($res) == 1)
    {
    $_SESSION['username'] = $u;
    header("Location: membershome.php");
    }
    else
    {
        echo 
    "You entered an incorrect username and/or password. <a href=\"index.php\">Try again.</a>";
    }
    ?>
    And logout.php clears our sessions variables, affectively logging the member out
    PHP Code:
    <?php session_start();
    header("Cache-control: private");
    unset(
    $_SESSION['username']);
    session_destroy();
    echo 
    "You have now logged out, <a href=\"index.php\">Login again</a>.";
    ?>
    And finally, membershome.php is a slightly small variation of index.php
    PHP Code:
    <?php session_start();
    header("Cache-control: private");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Member System - member centre</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    </head>

    <body>

    <h1>Welcome <?php echo $_SESSION['username']; ?></h1>

    <?php

    if(isset($_SESSION['username']))
        {
    ?>
    Yay, <?php echo $_SESSION['username']; ?> is logged in.

    <br /><br />

    <a href="logout.php">Logout</a>

    <?php

    }
        else
            {
    ?>

    <form name="login" action="login.php" method="post">

    Username: <input type="text" size="30" name="username" />

    <br /><br />

    Password: <input type="password" size="30" name="password" />

    <br /><br />

    <input type="submit" name="submit" value="Login" />

    </form>

    <?php
    }
    ?>

    </body>
    </html>
    Notes
    1: Once you have executed install.php successfully, you will need to insert at least one entry into the table. Also, for the password, the value must be encoded using md5. Use http://www.adamek.biz/md5-generator.php to encode the password you want.
    2: This script is basic, there is no way to allow possible members to register with your website, nor is there a way to update a members details when logged in.

    And that is your basic membership system.

  2.  

  3. #2
    Senior Member simpleurl's Avatar
    Join Date
    Jul 2006
    Location
    Leicester, UK.
    Posts
    150
    Member #
    13598
    Nice tutorial Would you mind if i put this tutorial on my website giving the credit to you for writing it?

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Go ahead, but just bare in mind it is basic.

    Mainly due to the countless other features that are needed, but I guess its the building blocks.

    The names bfsog

  5. #4
    Senior Member simpleurl's Avatar
    Join Date
    Jul 2006
    Location
    Leicester, UK.
    Posts
    150
    Member #
    13598
    Ok I will add a little more to it as well thanks.

  6. #5
    Senior Member Karloff's Avatar
    Join Date
    Oct 2005
    Posts
    744
    Member #
    11702
    :thumbsup:

  7. #6
    Junior Member
    Join Date
    Oct 2007
    Posts
    2
    Member #
    16054
    Nice tutorial! Do you mind if I put this on my website as well, of course giving you full credit to it?

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Not at all, bare in mind that was posted a year ago, may not be as up to date as it could be.

  9. #8
    Junior Member kozmana's Avatar
    Join Date
    Jul 2008
    Location
    Tbilisi, Georgia
    Posts
    1
    Member #
    17097
    But, if I add the registration file? I think this is very good system,

  10. #9
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    It's alright, It was written a while ago but the premise is solid I suppose.

    www.opensourcecms.com and www.hotscripts.com are full of scripts you could look into.

  11. #10
    Junior Member
    Join Date
    Jul 2008
    Location
    United Kingdom
    Posts
    3
    Member #
    17067
    Nice and basic, everyone starts somewhere

    check out mine

    www.JamesHemsley.com/MemberSystem

    user: demo
    pass: demo

    Going to be creating some add ons & plugins soon.


Remove Ads

Posting Permissions

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

Search tags for this page

create a membership system php
,
create php membership
,
free member system script
,
free php membership system
,
how to create member system in php
,
how to create membership in php
,

html member system

,
html membership system
,
membership system in html
,

system membership php create

Click on a term to search for related topics.
All times are GMT -6. The time now is 01:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com