Skip to content

Instantly share code, notes, and snippets.

@rizkyramadhan21
Created February 14, 2018 13:37
Show Gist options
  • Save rizkyramadhan21/44e83d2cb09b4c5398e4b396a2ed83e8 to your computer and use it in GitHub Desktop.
Save rizkyramadhan21/44e83d2cb09b4c5398e4b396a2ed83e8 to your computer and use it in GitHub Desktop.
<?php
/*
------------------------------------------------------
login-validasi.php: menangkap variable yang dikirimkan
pada file login.php
------------------------------------------------------
*/
require_once '../config/config.php';
if ( isset($_POST['username']) && isset($_POST['password']) ) {
$sql_check = "SELECT id,
telegram_id
FROM users
WHERE
username=?
AND
password=?
LIMIT 1";
$check_log = $db->prepare($sql_check);
$check_log->bind_param('ss', $username, $password);
$username = $_POST['username'];
$password = md5( $_POST['password'] ); //enkripsi md5 just for example
$check_log->execute();
$check_log->store_result();
if ( $check_log->num_rows == 1 ) {
$check_log->bind_result($id, $telegram_id, $auth_code);
// This is user session:
while ( $check_log->fetch() ) {
$_SESSION['user_login'] = $username;
$_SESSION['telegram_id'] = $telegram_id;
}
$check_log->close();
// Jika berhasil login, maka akan diarahkan ke laman autentikasi
header("location: autentikasi.php");
exit();
// Jika gagal tetap di laman login dan menampilkan error
} else {
header('location: login.php?err='.base64_encode('Invalid Username or Password!'));
exit();
}
} else {
header('location:login.php');
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment