• Home
  • Hire me
Machine Language :: Human Language :: Our Language
not to hate, not to blame, but to understand
  • PHP
  • WordPress
    • WordPress Plugins
  • English
  • Bahasa Indonesia
  • Java
  • jQuery
  • Interlude
  • Lowongan Penulis
  • my twitter
  • my facebook
  • Machine Language :: Human Language :: Our Language
1

Multi-User Login with PHP and Mysql

November 20, 2010
by littleflow3r

Case Study : Creating a Multi-User Login System with PHP and Mysql.

Requirements : Webserver Packages (AppServ, XAMPP, EasyPHP, etc)

Step 1 : Preparing the Database

  1. Prepare a database with the name db_multiuser.
  2. Create a table named tb_user, create the fields – fields like the following picture,

    Struktur Tabel

  3. Insert some sample data to tb_user.
    INSERT INTO `db_multiuser`.`tb_user` (`id`, `username`, `password`, `tipe`) VALUES (NULL, 'ani', 'ani','admin'), (NULL, 'budi', 'budi', 'operator');

Step 2 :Create the configuration file

  1. Type the following script,
    <?php
    $host = "localhost";
    $user = "root"; //adjust to your mysql user

    $pass = ""; //i use no password in my mysql
    $dbName = "db_multiuser";
    mysql_connect($host, $user, $pass);
    mysql_select_db($dbName)
    or die ("Connect Failed : ".mysql_error());
    ?>
  2. Save with the name connect.php
  3. Explanation: connect.php is a configuration file that would link the login system that we created with mysql database.

Step 3 :Create the login form

  1. Type the following script,
    <center>
    <h2> <b> Login Page </b> <h2><form method="post" action="proses.php"><table border="0" align="center" cellpadding="5" cellspacing="8"><tr bgcolor="orange">
    <td> UserName! </td>
    <td> <input name="username" type="text"> </td>
    </tr>
    <tr bgcolor="orange">
    <td> Password ! </td>
    <td> <input name="password" type="password"> </td>
    </tr>
    <tr>
    <td> &nbsp; </td>
    <td> <input name="submit" type="submit" value="login"> </td>
    </tr>
    </table>
    </form>
    </center>
  2. Save with the name formlogin.php
  3. This script will display a login form for username and password fields. Consider the action="proses.php". This shows that the entries from the username and password will be processed (given the action) by proses.php file. This file will be created in the next step.

Step 4 :Create the processing file for login

  1. Type the following script,
    <?php
    session_start(); //startsession
    include "connect.php";//get the username and password from the form
    $username = $_POST['username'];
    $password = $_POST['password'];
    //query for retrieve the user data from database according to username in the form
    $q = "SELECT * FROM tb_user WHERE username = '$username' ";
    $result = mysql_query($q);
    $data = mysql_fetch_array($result);
    //checking the password
    if ($password == $data['password']) {
    //save usertype & username in the session
    $_SESSION['tipe'] = $data['tipe'];
    $_SESSION['username'] = $data['username'];
    include "menu.php";
    }
    //If password doesnt match
    else {
    $warning = "Wrong Username / Password";
    echo $warning;
    }
    ?>
  2. Save with the name proses.php

Step 5 : Make a display special for user

  1. Type the following script,
    <?php
    session_start();
    include "connect.php";
    echo "<center>";
    echo "<h3> Menu </h3>";
    if ($_SESSION['tipe'] == "admin") {
    echo " Anda Login sebagai Admin";
    }
    else if ($_SESSION['tipe'] == "user") {
    echo " Anda Login sebagai User";
    }
    ?>
  2. Save with the name menu.php
  3. Explanation: This script will display the information in accordance with the users who are logged.

Step 6 : Running the Login System

  1. Go to http://localhost/
  2. Select file formlogin.php to start running the application. You will see a display like the following,

    Login Page

  3. Set the username = ani; password = ani
  4. System will display the description as follows,

    Admin Login

  5. If you log in as an operator (username: budi; password: budi), it will display information as shown below,

    Operator Login

NB. Save all the php file from step 2 – step 5 into the SAME ONE folder.

Okay then, happy coding (:
Others that might interesting too:

Copyright

All scripts and techniques demonstrated on itx.web.id can be used in whatever manner you wish without attribution. You cannot copy whole tutorials, either in English or translated to another language.

This post is also available in: Indonesian


Related Articles:

  • The Use of Date/Time Function in PHPThe Use of Date/Time Function in PHP
  • Sistem Login simple MD5 (+Logout) dengan CodeIgniterSistem Login simple MD5 (+Logout) dengan CodeIgniter
  • Tutorial Searching / Pencarian Data dengan PHP dan MysqlTutorial Searching / Pencarian Data dengan PHP dan Mysql
  • Tutorial Searching Data with PHP and MysqlTutorial Searching Data with PHP and Mysql
  • GuestBook Sederhana dengan PHP &amp; MysqlGuestBook Sederhana dengan PHP &amp; Mysql
  • Efisien Code Menggunakan PHP IncludeEfisien Code Menggunakan PHP Include
: PHP
: login multi user, mysql, PHP

About the author

obviously, a girl. with sweet smile, off course. turning her 21 years trapped on Informatics departement and just started to having some crush with it lately. she uses wordpress. she loves php. she lo
littleflow3r.wordpress.com/

1 Comment

  • afrilia says:
    February 20, 2012 at 3:54 pm

    (scenic)
    bagus bgt ne…patut dicoba

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

RSS feed for this post (comments) · TrackBack URI
Previous Post
« Running Query SQL with PHP
Next Post
Create a Form in the WordPress with CForms Plugin »
  • Like itx.web.id?
  • Domba Garut
    Benih Cabe Terpedas di Dunia
    Benih Sorgum Unggul
    Benih Terong
    Benih Okra
    Beras Hitam Organik
    Benih Beras Hitam
  • Search

    • Hai
    • Posts
    • Comments
    Inilah blog itx.... seorang yang suka pemrograman web khususnya PHP dan WordPress... jangan ragu tinggalkan pesan di sini ... :)
    Sebagian besar artikel di sini tidak saya tulis, melainkan ditulis oleh teman-teman author (penulis lepas). Jadi kalo menyapa jangan salah alamat yaaa... lihat dulu siapa penulis artikel ybs.
    • Create Multi-User in WordPress CMS
    • Instant Sorting Function with PHP
    • Installing New Theme in WordPress CMS
    • Create Page (Statis Post) in WordPress (Beginner Only)
    • Code Igniter : Export Data into PDF File
    • String Functions in the PHP
    • Get the Data from Database with Codeigniter and Show it with JQuery UI Tab
    • Round Number in PHP
    • Put Flickr Album Photos in to WordPress
    • Upload Image in to WordPress Post (for Beginner)
    • Evan Arnone: In case you are however on the fence: snatch your headphones, top of your head as a result of any ...
    • Flossie Hugueley: Selection of color styles can be found subjected to this important. It is very with regards to 100% Pima cotton. ...
    • http://www.plungebobplumbing.co.uk/services/bathroom-design-installation/: I know this if off topic but I'm looking into starting my own weblog and was curious what all is ...
    • Awilda Mimaki: I wanted to send you that bit of observation to help say thank you yet again just for the lovely ...
    • astuces pour maigrir: My partner and I stumbled over here coming from a different web page and thought I might check things out. I ...
    • custom decals: I am extremely impressed with your writing skills as well as with the layout on your blog. Is this a ...
    • Rolf Brennecke: I vary with a lot of folks here; I came across this web site submit I couldn't quit right up ...
    • Chiropractor in Kent: I recently discovered the post and possess been studying together. I ought to show our enjoy of your generating expertise ...
    • click for more: I am really enjoying the theme/design of your website. Do you ever run into any web browser compatibility problems? A ...
    • Chiropractic Kent: I must say your post is really good and has taken my attention towards it to read it completely; its ...
    • Audrie Laroe: Its like you read my mind! You appear to know so much about this, like you wrote the book in ...
    • http://www.plungebobplumbing.co.uk/services/bathroom-design-installation/: Thanks to you for stating this to us. You shared a highly informative post here.. Well done!
    • mobile gis mapping: Your web page is very beneficial. Thank you relating to providing lots of valuable content. We've book marked your blog ...
    • Latisha Nunez: But wanna say that this is very helpful , Thanks for taking your time to write this. "The ...
    • Fredric Gunzelman: I enjoy your writing style truly enjoying this internet site. "Slow and steady wins the race." by Robert Lloyd.
  • Postingan populer

    • Tutorial Upload, Menyimpan, dan Menampilkan Gambar dengan PHP dan Mysql
    • Tutorial Searching / Pencarian Data dengan PHP dan Mysql
    • Membuat Form ComboBox Dinamis dari Database (Mysql) dengan PHP
    • Membuat Fungsi Update Data dalam Database dengan PHP Mysql
    • Form Input Tanggal PHP dengan Datetimepicker JQuery
    • Login Multi-User dengan PHP dan Mysql
    • Penggunaan Fungsi Date / Time pada PHP
  • Tags

    ajax tab ceil checkbox delete multiple data codeigniter login system codeigniter pagination code igniter pdf date time function delete function with php dynamic combobox export database to excel export to pdf floor image GD library image thumbnail include php install wordpress login codeigniter login system login with md5 metadata wordpress object oriented php oop php php codeigniter php round posting code in the wordpress searching script simple mobile tab thumbnail version update data with php xml to database
    • en  English
    • id  Indonesia
  • Themes made by itx

    Albizia Theme
    - Download Albizia

    Bombax Theme
    - Download Bombax

    Calotropis Theme
    - Download Calotropis

  • Plugins made by itx

    Exclude Plugins
    - Download Exclude Plugins

  • Jika memiliki pertanyaan tentang theme atau plugin buatan itx, silahkan menuju forum.
  • Business Directory
    Benih Alfalfa
    Benih Terong Gendut
    Benih Cabe Terpedas & Terunik di Dunia
    Benih Mawar beraneka warna unik

Machine Language :: Human Language :: Our Language
Bombax Theme designed by itx