PHP Tutorial
Advanced PHP
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- PHP - Coding Standard
- PHP - File Uploading
- PHP - Sending Emails
- PHP - Sessions
- PHP - Cookies
- PHP - Functions
- PHP - Files & I/O
- PHP - File Inclusion
- PHP - GET & POST
- PHP - Web Concepts
- PHP - Strings
- PHP - Arrays
- PHP - Loop Types
- PHP - Decision Making
- PHP - Operator Types
- PHP - Constants
- PHP - Variable Types
- PHP - Syntax Overview
- PHP - Environment Setup
- PHP - Introduction
- PHP - Home
Advanced PHP
- PHP - For PERL Developers
- PHP - For C Developers
- PHP - Object Oriented
- PHP & XML
- PHP & AJAX
- PHP & MySQL
- PHP - Date & Time
- PHP - Bugs Debugging
- PHP - Error Handling
- PHP - Regular Expression
- PHP - Predefined Variables
PHP Form Examples
PHP login Examples
PHP AJAX Examples
PHP XML Example
- PHP - DOM Parser Example
- PHP - SAX Parser Example
- PHP - Simple XML GET
- PHP - Simple XML
- PHP - XML Introduction
PHP Frame Works
PHP Design Patterns
PHP Function Reference
PHP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PHP - Login Example
PHP - Login Example
PHP login with session
Php login script is used to provide the authentication for our web pages. the Script executes after submitting the user login button.
Login Page
Login page should be as follows and works based on session. If the user close the session, it will erase the session data.
<?php ob_start(); session_start(); ?> <? // error_reporting(E_ALL); // ini_set("display_errors", 1); ?> <html lang = "en"> <head> <title>Tutorialspoint.com</title> <pnk href = "css/bootstrap.min.css" rel = "stylesheet"> <style> body { padding-top: 40px; padding-bottom: 40px; background-color: #ADABAB; } .form-signin { max-width: 330px; padding: 15px; margin: 0 auto; color: #017572; } .form-signin .form-signin-heading, .form-signin .checkbox { margin-bottom: 10px; } .form-signin .checkbox { font-weight: normal; } .form-signin .form-control { position: relative; height: auto; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 10px; font-size: 16px; } .form-signin .form-control:focus { z-index: 2; } .form-signin input[type="email"] { margin-bottom: -1px; border-bottom-right-radius: 0; border-bottom-left-radius: 0; border-color:#017572; } .form-signin input[type="password"] { margin-bottom: 10px; border-top-left-radius: 0; border-top-right-radius: 0; border-color:#017572; } h2{ text-apgn: center; color: #017572; } </style> </head> <body> <h2>Enter Username and Password</h2> <span class = "container form-signin"> <?php $msg = ; if (isset($_POST[ login ]) && !empty($_POST[ username ]) && !empty($_POST[ password ])) { if ($_POST[ username ] == tutorialspoint && $_POST[ password ] == 1234 ) { $_SESSION[ vapd ] = true; $_SESSION[ timeout ] = time(); $_SESSION[ username ] = tutorialspoint ; echo You have entered vapd use name and password ; }else { $msg = Wrong username or password ; } } ?> </span> <!-- /container --> <span class = "container"> <form class = "form-signin" role = "form" action = "<?php echo htmlspecialchars($_SERVER[ PHP_SELF ]); ?>" method = "post"> <h4 class = "form-signin-heading"><?php echo $msg; ?></h4> <input type = "text" class = "form-control" name = "username" placeholder = "username = tutorialspoint" required autofocus></br> <input type = "password" class = "form-control" name = "password" placeholder = "password = 1234" required> <button class = "btn btn-lg btn-primary btn-block" type = "submit" name = "login">Login</button> </form> Cpck here to clean <a href = "logout.php" tite = "Logout">Session. </span> </body> </html>
Logout.php
It will erase the session data.
<?php session_start(); unset($_SESSION["username"]); unset($_SESSION["password"]); echo You have cleaned session ; header( Refresh: 2; URL = login.php ); ?>
It will produce the following result −
Advertisements