Weiterleitung nach erstem Login?
Guten Tag und frohe Weihnachten. Meine Frage: ich habe vor ein paar Tagen schon einmal von einer Personengrenze in PHP gesprochen. Jedoch bin ich mit meinem Latein am Ende, da ich eher front-end Entwickler bin. Hätte vielleicht jemand einen Code-schnipsel mit dem ich nach einem Login ein timeout setze dass sich für 30 Sekunden niemand anmelden kann? Sollte dann logischerweise auf eine andere Seite weitergeleitet werden für Load-balance.
login:
<?php
include "config.php";
if(isset($_POST['but_submit'])){
$uname = mysqli_real_escape_string($con,$_POST['txt_uname']);
$password = mysqli_real_escape_string($con,$_POST['txt_pwd']);
if ($uname != "" && $password != ""){
$sql_query = "select count(*) as cntUser from users where username='".$uname."' and password='".$password."'";
$result = mysqli_query($con,$sql_query);
$row = mysqli_fetch_array($result);
$count = $row['cntUser'];
if($count > 0){
$_SESSION['uname'] = $uname;
header('Location: show.php');
}else{
echo "Falscher PIN-Code. Bitte versuche es nocheinmal oder lass es.";
}
}
}
?>
Crypt Seite:
<?php
include "config.php";
$timeout = 10;
//Set the maxlifetime of the session
ini_set( "session.gc_maxlifetime", $timeout );
//Set the cookie lifetime of the session
ini_set( "session.cookie_lifetime", $timeout );
// Check user login or not
if(!isset($_SESSION['uname'])){
header('Location: login.php');
}
// logout
if(isset($_POST['but_logout'])){
session_destroy();
header('Location: login.php');
}
session_start();
//Set the default session name
$s_name = session_name();
//Check the session exists or not
if(isset( $_COOKIE[ $s_name ] )) {
setcookie( $s_name, $_COOKIE[ $s_name ], time() + $timeout, '/' );
}
else
header("Location: login.php");
?>
programmieren,
PHP