PHP Classes

File: Login_examples.php

Recommend this page to a friend!
  Classes of Dariusz   PHP Registration and Login   Login_examples.php   Download  
File: Login_examples.php
Role: Example script
Content type: text/plain
Description: Examples of using Login class
Class: PHP Registration and Login
Manage user registrations and authentication
Author: By
Last change:
Date: 10 years ago
Size: 1,416 bytes
 

Contents

Class file image Download
<?php
   
require_once "Login.php";
   
header("Content-Type: text/html; charset=UTF-8");
   
   
$dsn = "mysql:host=.....;dbname=.....";
   
$username = ".....";
   
$password = ".....";
   
    try {
       
$pdo = new PDO($dsn, $username, $password);
       
$pdo->query("SET NAMES utf8");
       
$pdo->query("SET CHARACTER_SET utf8_polish_ci");
       
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   
   
       
// Próba logowanie i pobieranie wartości
   
       
if (Login::getLogin()) {
            echo
"Logout..";
           
Login::logout();
           
var_dump(Login::checkSession());
            echo
"<br/>";
        }
       
$login = new Login($pdo);
   
        echo
"Logowanie...<br/>";
       
$login->login(".....", ".....");
   
       
/*
         * Errory are indexed like that:
        * username => "error about username"
        * password => "error about password"
        * data => "error about data correctness"
        */
       
if ($login->hasErrors()) {
            die(
var_dump($login->getErrors()));
        }
   
        echo
Login::getName() . "<br/>";
        echo
Login::getId() . "<br/>";
        echo
Login::getType() . "<br/>";
   
       
var_dump(Login::checkSession());
        echo
"<br/>";
       
var_dump(Login::getInfo());
        echo
"Logout...<br/>";
       
Login::logout();
       
var_dump(Login::checkSession());
   
   
   
        exit;
        echo
"Next login...";
       
$login->login(".....", ".....");
       
var_dump(Login::checkSession());
   
    }
    catch(
PDOException $e) {
        echo
"PDO library error occured: " . $e->getMessage();
    }
?>