04html form get post login system

Upload: geshan-manandhar

Post on 30-May-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 04html Form Get Post Login System

    1/12

    GeshanManandhar.comGeshanManandhar.com 11

    PHP Day 4PHP Day 4

    Geshan ManandharGeshan ManandharDeveloper,Developer,

    Young Innovations Private LimitedYoung Innovations Private Limited

    www.geshanmanandhar.comwww.geshanmanandhar.com

    http://www.php.net

  • 8/14/2019 04html Form Get Post Login System

    2/12

    GeshanManandhar.com 2

    HTML FormsHTML Forms

    .

    For display formatted forms use tables.For display formatted forms use tables.

    For more seeFor more see

    http://www.w3schools.com/html/html_forms.asphttp://www.w3schools.com/html/html_forms.asp

    http://www.w3schools.com/html/html_forms.asphttp://www.w3schools.com/html/html_forms.asphttp://www.w3schools.com/html/html_forms.asp
  • 8/14/2019 04html Form Get Post Login System

    3/12

    GeshanManandhar.com 3

    Require and IncludeRequire and Include

    require(path/to/file_name.php)require(path/to/file_name.php)

    include(path/to/file_name.php)include(path/to/file_name.php) Difference is require will throw a Fatal error isDifference is require will throw a Fatal error is

    file required is not found include will justfile required is not found include will justthrow a warning.throw a warning.

    require_once(path/to/file_name.php);require_once(path/to/file_name.php);

    include_once(path/to/file_name.php);include_once(path/to/file_name.php);To require or include a file just once.To require or include a file just once.

  • 8/14/2019 04html Form Get Post Login System

    4/12

    GeshanManandhar.com 4

    Session ManagementSession Management

    session_start Initialize session datasession_start Initialize session data

    $_SESSION[index] = value;$_SESSION[index] = value;

    $_SESSION[user_name] = $user_name;$_SESSION[user_name] = $user_name;session_destroy Destroys all datasession_destroy Destroys all data

    registered to a sessionregistered to a session

  • 8/14/2019 04html Form Get Post Login System

    5/12

    GeshanManandhar.com 5

    A simple login interfaceA simple login interface

  • 8/14/2019 04html Form Get Post Login System

    6/12

    GeshanManandhar.com 6

    Login Check functionLogin Check function

    Getting Variables and starting session.Getting Variables and starting session.

  • 8/14/2019 04html Form Get Post Login System

    7/12

    GeshanManandhar.com 7

    Login Check functionLogin Check function

    The Function definitionThe Function definition

    function check_login($user_name, $pass_word){function check_login($user_name, $pass_word){

    if(($user_name=="admin") && ($pass_word === "test"))if(($user_name=="admin") && ($pass_word === "test"))

    {{

    //set session//set session

    $_SESSION['user_name'] = $user_name;$_SESSION['user_name'] = $user_name;$_SESSION['user_logged_in'] = true;$_SESSION['user_logged_in'] = true;return 1;return 1;

    }}

    else{else{return 0;return 0;

    }}

    }}

  • 8/14/2019 04html Form Get Post Login System

    8/12

    GeshanManandhar.com 8

    Login check functionLogin check function

    Function call and processFunction call and process$user_ok = check_login($user_name, $pass_word); //called from$user_ok = check_login($user_name, $pass_word); //called from

    check_login_function.phpcheck_login_function.php

    if($user_ok){if($user_ok){

    header("Location: logged_in.php"); /* Redirect browser */header("Location: logged_in.php"); /* Redirect browser */

    }}

    else {else {

    header("Location: not_logged_in.php");header("Location: not_logged_in.php");

    }}

    ?>?>

  • 8/14/2019 04html Form Get Post Login System

    9/12

    GeshanManandhar.com 9

    Either you login or are notEither you login or are not

    logged inlogged in

  • 8/14/2019 04html Form Get Post Login System

    10/12

    GeshanManandhar.com 10

    Session to authenticate usersSession to authenticate users

    Address security issues.Address security issues.

    Put content that should be seen byPut content that should be seen by

    logged in users or even by user type.logged in users or even by user type.

    User module and session managementUser module and session management

    is essential to almost every system.is essential to almost every system.

  • 8/14/2019 04html Form Get Post Login System

    11/12

    GeshanManandhar.com 11

    QuestionsQuestions

  • 8/14/2019 04html Form Get Post Login System

    12/12

    GeshanManandhar.com 12

    Lets start practiceLets start practice

    Build your own login system with upto 3Build your own login system with upto 3user name and password combinationuser name and password combination

    with user of array,with user of array, refer to code ofrefer to code of

    Day04Day04..Among the 3 one should be of typeAmong the 3 one should be of type

    admin and remaining two of type user.admin and remaining two of type user.

    The logged in page should not beThe logged in page should not beaccessible directly after typing fullaccessible directly after typing fullURL/address in the address bar.URL/address in the address bar.