• 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:

  • Penggunaan Fungsi Date / Time pada PHPPenggunaan Fungsi Date / Time pada PHP
  • Simple Guest Book with PHP &amp; MysqlSimple Guest Book with PHP &amp; Mysql
  • Create Thumbnail Version from Image with PHPCreate Thumbnail Version from Image with PHP
  • Menghitung Karakter TextArea dalam Form PHPMenghitung Karakter TextArea dalam Form PHP
  • Delete Mysql Data Function with PHPDelete Mysql Data Function with PHP
  • Get the Data from Database with Codeigniter and Show it with JQuery UI TabGet the Data from Database with Codeigniter and Show it with JQuery UI Tab
: 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 Alfalfa
    Beras Organik
  • 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)
    • kiki: sangat bermanfaat..
    • fdrock: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\skripsi\delete.php on line 5
    • Dary Pradipta: masih berlaku kah ini mas ??
    • mausul: assalam alaikum,,, cuma salam kenal... dan mau tanya gimana cara apat tema kaya milik blog ini, bisa nggak tema ini dipakai ...
    • rio: kk q dh daftar pi confirm emailnya kok lama ea kk user name ku riosaragi88
    • ReneeSturn: selamat malam saya username : ReneeSturn ingin menjadi penulis. Karya tulis PHP di post dimana?
    • Dwi: @yang punya web: bang kok ni script ke hapus sih ke hapus tapi gk ada pesan Are You Sure to ...
    • Ridho Ramidianto: id : ridho-r
    • Ridho Ramidianto: saya ingin jadi penulis,.. ? gmana ?
    • Sonia: Masih bisakah dicoba? Thanks, Sonia
    • gendut_79: Salam Admin Saya sudah mendaftar atas nama : gendut_79 Mohon dijadikan AUTHOR Terima kasih
    • rani r: saya berminat untuk menulis disini
    • arism: halo min, udah daftar nih, id arism. ditambah jadi author ya.
    • FARA DILA SANDY: pengen punya kerjaan sambilan.,., gg dibayar sementara juga gag pa.,., pengalaman dulu :)
    • eisthon: saya sudah menjadi anggota. bagaimana cara untuk mulai menulis...mohon penjelasan..thanks???!
  • Postingan populer

    • Tutorial Upload, Menyimpan, dan Menampilkan Gambar dengan PHP dan Mysql
    • Membuat Form ComboBox Dinamis dari Database (Mysql) dengan PHP
    • Tutorial Searching / Pencarian Data dengan PHP dan Mysql
    • Form Input Tanggal PHP dengan Datetimepicker JQuery
    • Membuat Fungsi Update Data dalam Database dengan PHP Mysql
    • 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 Asparagus
    Benih Chicory
    Bedak Saripohatji

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