Last active
March 1, 2016 15:13
-
-
Save suciptoid/bdd30e036374ac2c6c65 to your computer and use it in GitHub Desktop.
Simple PHP Login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php session_start(); | |
if(isset($_SESSION['username'])){ | |
echo "Hi Admin, user kamu ".$_SESSION["username"]; | |
}else{ | |
header('Location: index.php'); | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php session_start(); | |
error_reporting(0); | |
// Login Logic | |
$post_user = $_POST["user"]; | |
$post_pass = $_POST["pass"]; | |
if(isset($post_user) && isset($post_pass)){ | |
check_login($post_user,$post_pass); | |
} | |
// Jika Logout | |
if(isset($_GET["logout"])){ | |
session_destroy(); | |
header('Location: index.php'); | |
} | |
// Chek user udah login belum | |
if(isset($_SESSION["username"])){ | |
echo "Anda login sebagai ".$_SESSION["username"]." <a href='?logout=true'>Metu</a>"; | |
} | |
// Function | |
function check_login($username,$pass){ | |
$base_user = "admin"; | |
$base_pass = "admin"; | |
if($username == $base_user && $pass == $base_pass){ | |
// Set sesi login | |
$_SESSION["username"] = $username; | |
}else{ | |
echo "Wadefak, lali password e?"; | |
} | |
} | |
?> | |
<form action="index.php" method="post"> | |
<input type="text" name="user"/> | |
<input type="password" name="pass"/> | |
<input type="submit" name="Login"/> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment