“System logowania PHP” Kod odpowiedzi

Jak utworzyć plik dziennika w PHP?

<?php
//Something to write to txt log
$log  = "User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
        "Attempt: ".($result[0]['success']=='1'?'Success':'Failed').PHP_EOL.
        "User: ".$username.PHP_EOL.
        "-------------------------".PHP_EOL;

//Save string to log, use FILE_APPEND to append.
file_put_contents('./log_'.date("j.n.Y").'.log', $log, FILE_APPEND);
Lozza

Zaloguj się PHP

<!DOCTYPE html>  
 <html>  
      <head>  
           <title>Webslesson Tutorial</title>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
           <script src="jquery.js"></script>  
           <style>  
                #box  
                {  
                     width:600px;  
                     background:gray;  
                     color:white;  
                     margin:0 auto;  
                     padding:10px;  
                     text-align:center;  
                }  
           </style>  
      </head>  
      <body>  
      <?php  
      session_start();  
      if(isset($_SESSION["name"]))  
      {  
           if((time() - $_SESSION['last_login_timestamp']) > 60) // 900 = 15 * 60  
           {  
                header("location:logout.php");  
           }  
           else  
           {  
                $_SESSION['last_login_timestamp'] = time();  
                echo "<h1 align='center'>".$_SESSION["name"]."</h1>";  
                echo '<h1 align="center">'.$_SESSION['last_login_timestamp'].'</h1>';  
                echo "<p align='center'><a href='logout.php'>Logout</a></p>";  
           }  
      }  
      else  
      {  
           header('location:login.php');  
      }  
      ?>  
      </body>  
 </html>
Crazy Coders

System logowania PHP

<?php
session_start();
if(!isset($_POST['pass'])){
    header("Location: index.html");
    exit();
}

$login = $_POST['login'];
$pass = $_POST['pass'];
$login = htmlentities($login, ENT_HTML5, "UTF-8");
$pass = htmlentities($pass, ENT_HTML5, "UTF-8");
require_once "../../includes/connect.php";
try{
    $db = new mysqli($host, $db_user,$db_pass, $db_name);
    if(!$db->connect_errno == 0){
        throw new Exception("connection error");
    }else{
        $query = "SELECT * FROM users WHERE user = ?";
        if(!$exec = $db->prepare($query)){
            throw new mysqli_sql_exception("Query prepare error");
        }else{
            $exec->bind_param("s", $login);
            $exec->execute();
            $res = $exec->get_result();
            $assoc = $res->fetch_assoc();
            if($res->num_rows != 0){
                if(!password_verify($pass,$assoc['pass'])){
                    $_SESSION['error'] = "incorrect login or pass";
                    header("Location: ../../index.html");
                }else{
                    $_SESSION['name'] = $assoc['name'];
                    $_SESSION['surname'] = $assoc['surname'];
                    $_SESSION['desription'] = $assoc['opis'];
                    $_SESSION['role'] = $assoc['role'];
                    if($assoc['isAdmin']){
                        $_SESSION['admin'] = true;
                        header("Location: ../../AdminPanel.php");
                    }else{
                        $_SESSION['loged'] = true;
                        header("Location: ../../User.php");
                    }
                }
            }else{
                $_SESSION['error'] = "Invalid login or Pass";
                header("Location: ../../index.html");
            }
        }
    }
}catch(Exception $e){
    echo $e;
}catch(mysqli_sql_exception $e){
    echo $e;
}
i have no idea

Odpowiedzi podobne do “System logowania PHP”

Pytania podobne do “System logowania PHP”

Więcej pokrewnych odpowiedzi na “System logowania PHP” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu