PHP Classes

File: examples/recover.php

Recommend this page to a friend!
  Classes of Oleg Zorin   PHP User Login class   examples/recover.php   Download  
File: examples/recover.php
Role: Example script
Content type: text/plain
Description: Recover demo
Class: PHP User Login class
Register, login and recover users in a database
Author: By
Last change: User. SQL driver misprint fix
Date: 6 years ago
Size: 3,208 bytes


Class file image Download
    * OZ\User login demo

/* make it short */
use OZ\User as User;
/* Mysql access */
$sql_driver = 'mysql';
$sql_host = 'localhost';
$sql_name = '';
$sql_user = 'root';
$sql_pass = '';
User::init($sql_driver, $sql_host, $sql_name, $sql_user, $sql_pass);
/* check current user */
$user = false;
User::check()) {
/* redirect to user account */
header('Location: account.php');

/* default values */
$login = '';
$password = '';
/* login routine */
$recover_error = array();
$_POST['recover'])) {
$login = !empty($_POST['login']) ? $_POST['login'] : '';
$error_flag = false;
$login)) {
/* login is required */
$recover_error['login'] = 'Login is required';
$error_flag = true;
/* We shouldn't check existence of login! */
        /* all checks passed */
if(!$error_flag) {
$password = User::recover($login);
$password)) {
$recover_error['general'] = implode('<br/>', User::getError());

        <title>User class demo. Recover</title>
        <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    <a class="navbar-brand" href="#">OZ\User demo</a>

                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="login.php">Login <span class="sr-only">(current)</span></a></li>
                        <li><a href="registration.php">Registration</a></li>
                        <li class="active"><a href="recover.php">Recover account</a></li>
        <div class="container">
            <div class="row">
                <div class="col-xs-12 col-sm-6 col-md-4 col-sm-offset-3 col-md-offset-4">
                    <form action="" method="post">
                        <div class="form-group">
                            <label for="login">Login</label>
                            <input type="text" class="form-control" name="login" id="login" placeholder="Login" value="<?php echo $login; ?>"/>
                            <?php if(!empty($recover_error['login'])) { ?>
                                <div class="alert alert-danger" role="alert"><?php echo $recover_error['login']; ?></div>
                            <?php } ?>
                        <button type="submit" name="recover" class="btn btn-primary">Recover</button>
                        <?php if(!empty($recover_error['general'])) { ?>
                            <div class="alert alert-danger" role="alert"><?php echo $recover_error['general']; ?></div>
                        <?php } ?>
<?php if(!empty($password)) { ?>
                            <div class="alert alert-success" role="alert">Your new password: <?php echo $password; ?>.<br/>(Send it to user mail)</div>
                        <?php } ?>