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 !

About: Aramis:
Web Developer and Module Developer for online web applications. Have great experience with Dolphin CMS.

Related posts:

  1. How to Easily Make a PHP Shoutbox Application
  2. How to Easily Make a PHP Chat Application
  3. Advance Level Php Tutorials and Scripts

Tags: , , , ,

admin

Web Developer and Module Developer for online web applications. Have great experience with Dolphin CMS.

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

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

  1. Legalsounds says:

    This is my first time I have visited your site. I found a lot of interesting information in your blog. From the tons of comments on your articles, I guess I am not the only one! keep up the impressive work.

  2. Hi Webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!Keep ‘em coming… you all do such a great job at such Concepts… can’t tell you how much I, for one appreciate all you do!

  3. That was a shocking article you posted.

  4. I love reading your web site.

  5. so well. Your site is well Believed out, graphically impressive and full of great Suggestions. Kudos.

  6. It´s all about fitness mates! Or what do you think? I like this site and it has given me some sort of inspiration to have success for some reason, so thank you. Moreover I´m definitely thinking about blogging these facts in my own blog!

  7. Amazing story, saved the site with hopes to see more information!

  8. Thanks very much for writing this excellent information! Looking forward to checking out more posts!

  9. Hi there! I really love reading your blog today! Keep making great posts and I will come back every day!!

  10. Hi there! I really love reading your blog today! Keep making great posts and I will come back every day to keep reading!

  11. I Adore it,Excellent Write-up.I am Make a decision to Fit this into use 1 of these days.Thank you for sharing this.To Your Success!

  12. Searscard says:

    Hello. I only did some net surfing and discovered this blog. I proceeded to go as a result of this web site post and it is actually amazing.I genuinely definitely delight in your web site.Perfectly, the article of writing is in confidence the very ideal on this really really worth even though subject. I book-marked it and i’m seeking forward to your impending website blogposts. I also seen that your web site has some very good connecting completed to it. I will correct apart take maintain of your rss feed to stay knowledgeable of any update versions. Amazing data you acquired here.If possible keep update in your fantastic submit.Regards.

  13. apb aimbot says:

    Do you have a blog feed I can subscribe to? I looked around but could not find it, thanks a ton in advance.

  14. Interesting understand, regards! My spouse and i finally capture the best ikon.

  15. I Too Like the Blog here. Keep up all the work. I too love to blog. This is great everyone sharing opinions :)

  16. Lyme Disease says:

    I believed i’d write and let you realize your content is advantageous for disclosed the handy method.I in reality love your weblog.Practically, the article is in truth the most beneficial on this worth despite the fact that subject. I concur with your results and will eagerly appear forward for your forthcoming updates. Only saying thanks is not going to just be adequate, for that brilliant lucidity in your own authoring. I will without delay pick up your rss feed to remain informed of any updates.Real deliver the results and a lot achievements in the give good results and small business endeavors.Regardless always keep up the good function.Thanks a lot.

  17. I really enjoyed reading this post. We (as a community), appreciate it. I have a similar blog on this topic. Do you mind if I link to this post on my internet site?

  18. This website just created my week! I were seeking close to for info on this. I’m glad now that I ran across this webpage. Woohoo!

  19. ffxiv hacks says:

    Hehe — I had to read it a few times, but it finally made sense :P

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>

Our writing Termpaperstar here Custom Term Papers most trusted. . edelsteine heilsteine