How to Easily Make an Advance Level Login system

How to Make an Advance Level Login system Easily with PHP
Today I will tell you about something new. This will useful and simple login system based on COOKIES. So we will store few info about logged member directly in cookies of browser. This technology help us to remember member

Here are Some samples:


So download the example files and lets start coding!


Step 1. HTML

As usual, we start with the HTML. This is login form code.

login_form.html

<form class="login_form" method="post" action="index.php">
    <div>Username: <input type="text" name="username" /></div>
    <div>Password: <input type="password" name="password" /></div>
    <div><input type="submit" value="Login" name="Login" /></div>
</form>
<div>You can use username "User1" of "User2" and password "qwerty" to login in system</div>

Step 2. CSS

Here are used CSS styles.

styles.css

.login_form {
    border: 1px solid #AAA;
    padding:10px;
}

Step 3. PHP

Now that we followed all the code on the front-end, it is now time for the last part of this tutorial – the PHP back-end.

As we can see – this is just pure class with functions for login system.

I used next functions:

getLoginBox – function return login form. In case if member logged – it will return Hello member record and possibility for logout

simple_login – perform login to system (storing necessary information in cookies)

simple_logout – perform logout (clearing used cookies)

check_login – return true in case if username and password exists in system

index.php

// initialization of login system and generation code
$oSimpleLoginSystem " new SimpleLoginSystem();
echo $oSimpleLoginSystem->getLoginBox();

// class SimpleLoginSystem
class SimpleLoginSystem {

    // variables
    var $aExistedMembers; // Existed members array

    // constructor
    function SimpleLoginSystem() {
        $this->aExistedMembers " array(
            'User1' "> 'd8578edf8458ce06fbc5bb76a58c5ca4',  //Sample: MD5('qwerty')
            'User2' "> 'd8578edf8458ce06fbc5bb76a58c5ca4'
        );
    }

    function getLoginBox() {
        ob_start();
        require_once('login_form.html');
        $sLoginForm " ob_get_clean();

        $sLogoutForm " '<a href""'.$_SERVER['PHP_SELF'].'?logout"1">logout</a>';

        if ((int)$_REQUEST['logout'] "" 1) {
            if (isset($_COOKIE['member_name']) && isset($_COOKIE['member_pass']))
                $this->simple_logout();
        }

        if ($_REQUEST['username'] && $_REQUEST['password']) {
            if ($this->check_login($_REQUEST['username'], MD5($_REQUEST['password']))) {
                $this->simple_login($_REQUEST['username'], $_REQUEST['password']);
                return 'Hello ' . $_REQUEST['username'] . '! ' . $sLogoutForm;
            } else {
                return 'Username or Password is incorrect' . $sLoginForm;
            }
        } else {
            if ($_COOKIE['member_name'] && $_COOKIE['member_pass']) {
                if ($this->check_login($_COOKIE['member_name'], $_COOKIE['member_pass'])) {
                    return 'Hello ' . $_COOKIE['member_name'] . '! ' . $sLogoutForm;
                }
            }
            return $sLoginForm;
        }
    }

    function simple_login($sName, $sPass) {
        $this->simple_logout();

        $sMd5Password " MD5($sPass);

        $iCookieTime " time() + 24*60*60*30;
        setcookie("member_name", $sName, $iCookieTime, '/');
        $_COOKIE['member_name'] " $sName;
        setcookie("member_pass", $sMd5Password, $iCookieTime, '/');
        $_COOKIE['member_pass'] " $sMd5Password;
    }

    function simple_logout() {
        setcookie('member_name', '', time() - 96 * 3600, '/');
        setcookie('member_pass', '', time() - 96 * 3600, '/');

        unset($_COOKIE['member_name']);
        unset($_COOKIE['member_pass']);
    }

    function check_login($sName, $sPass) {
        return ($this->aExistedMembers[$sName] "" $sPass);
    }
}

View Demo of our sample

download in package


Conclusion

I described one of easy and useful login system based on cookies. You can use this material to create own login systems into your startups. Good luck !

Tags: , , , ,

admin

Web Developer and Module Developer for online web applications

I wrote a total number of 3 articles on Script Tutorials.

10 Responses to “How to Easily Make an Advance Level Login system”

  1. designfloat.com says:

    How to Easily Make an Advance Level Login system…

    How to Easily Make an Advance Level Login system…

  2. How to Easily Make an Advance Level Login system – Script tutorials | Neorack Tutorials says:

    [...] the original: How to Easily Make an Advance Level Login system – Script tutorials Share and [...]

  3. Hermitbiker says:

    …. a tutorial for easily making an advance level login system…. cool !! Thanks Ayaz for sharing this amazingly helpful tutorial blog…. “Script-Tutorials.com” and I thank this site for all the really helpful help !! :)

  4. uberVU - social comments says:

    Social comments and analytics for this post…

    This post was mentioned on Twitter by Designzzz: How to Easily Make an Advance Level #PHP Login System – http://bit.ly/d84WXA...

  5. How to Easily Make an Advance Level Login system | AboutBrowsers.info says:

    [...] Read this article: How to Easily Make an Advance Level Login system [...]

  6. Atul Kash says:

    I believe open id and fconnect is the way to go.

  7. Dave says:

    Very helpful! Thank you! Looking forward to other “Script Tutorials.” I also like the way you have included a demo of the things you have covered in the tutorial!

    Dave

  8. Tweets that mention How to Easily Make an Advance Level Login system – Script tutorials -- Topsy.com says:

    [...] This post was mentioned on Twitter by PHP Web Developer, Aaron Bassett, Ayaz Malik, Andrey Prikaznov, Blue Baby and others. Blue Baby said: RT @Designzzz – How to Easily Make an Advance Level #PHP Login System – http://bit.ly/d84WXA [...]

  9. How to Easily Make an Advance Level Login system » DesignYelp – yelp and design says:

    [...] http://script-tutorials.com/advance-php-login-system-tutorial/ POPULAR ADS POPULARaccessibility accuracy Adobe advertising allot allure Amazing angularity Apple architecture are art article artist asterisk atleast attention base Below bit blog brand bunch business Business Cards campaign Canvas car century Chrome class Classic clock CMS code collection color com Committee    site community company composition Comprehensive computer concept content contest context CSS day depth design designer Designers Digital dimension disability distro doubt duty effect elegance element    screen everyone everything ExplorerCanvas feature Flash FlashMoto form framework Free Friedman gadget Ghia Google greenest group Hammer hand Hope Identity Illustration imagination impasto Impressive information Inspiration International Internet introduction Italdesign jQuery jsPlumb landscape LHS lighting    Black Linux list Little loading logo look lover magazine    message marketplace master moment movie networking nicest noisy nothing obligation Olympic online painting paper passion personality perspective Photography Photoshop Pininfarina place planning play Plenty plugin plumbing portfolio post poster Print prize process property quality rasterization ray reader reason roundup scheme script selection selector series showcase site SmashingMagazine software something source Space spirit Studios style success Supercar tablet technique template theme thing time today Tools tutorial Tutorials Twitter Ubuntu usability Vitaly vote wall watercolor way Web website WordPress work world year Zagato DesignYelp.com © 2010 [...]

  10. admin says:

    Thanks guys for comments :)
    Yes, OpenID and OAuth is good technologies too, but it will more difficult for first reading. But hope that I will create such articles too.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>