Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //session_start();
- include 'dbConnect.php';
- function loginaction(){
- include 'dbConnect.php';
- $time = time();
- if(isset($_REQUEST['login'])){
- $key = $_GET['telegram_key'];
- $json = '{"false":"index.html","a":" admin.php","b":"leader.php","c":"user.php"}';
- $query = $db->prepare("SELECT operators.operator_id, telegramlog.telegram_key FROM telegramlog LEFT JOIN operators ON telegramlog.operator_id = operators.operator_id WHERE telegramlog.telegram_key = ?, key_time = ? ;");
- $query->execute(array($key,$time));
- $result = $query->fetchAll();
- if(isset($_REQUEST['error'])){
- $error= $_REQUEST['error'];
- echo errorDefine($num);
- }
- statements ($time,$row,$result,$sResult,$db,$query,$squery);
- }
- else if (isset($_REQUEST['loginnorm'])){
- $username=$_REQUEST['user'];
- $password=$_REQUEST['pass'];
- $json = '{"false":"index.html","a":" admin.php","b":"leader.php","c":"user.php"}';
- if(isset($_REQUEST['error'])){
- $error= $_REQUEST['error'];
- echo errorDefine($err);
- }
- $squery = $db->prepare("SELECT * FROM operators WHERE email = ? and heslo = ?;");
- $sResult = $squery->execute(array($username,$password));
- statements($time,$sResult,$db,$squery,$result);
- }
- }
- function errorDefine($num){
- $json = '{"0":"špatné přihlášení","1":"čas vypršel","2":"prázdné pole","3":"asi vše funguje.."}';
- $err = json_decode($json, true);
- return $err[$num];
- }
- function statements($time,$sResult,$db,$squery,$result,$json){
- $redirects = json_decode($json, true);
- $result = $result[3];
- $sResult = $sResult[3];
- if($time > $row['key_time']){
- if($result){
- header('location: user.php');
- }
- }
- elseif($sResult){
- while($row = $squery ->fetch(PDO::FETCH_ASSOC)){
- echo '<script type="text/javascript">alert("You are logged in as user '. $row['users'] . '")</script>';
- if($row['users']=="a"){
- header('location: admin.php');
- }
- elseif($row['users']=="b"){
- header('location: leader.php');
- }
- elseif($row['users']=="c"){
- header('location: user.php');
- }
- else{
- return $redirects[$sResult['users']]."?err=2";
- }
- }
- }
- else if ($time < $row['key_time']) {
- header("location: function.php?error=1");
- }
- else if('empty'){
- header("location: function.php?error=3");
- }
- }
- loginaction();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement