Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- error_reporting(0);
- ############################ [Start connect] ###########################
- $connect = new mysqli("localhost","root","","tut_php");
- if($connect->connect_error){
- die("Error conect:".$connect->connect_error);
- }
- ############################ [End connect] #############################
- ############################ [Start Logout] ###########################################
- if($_GET['type'] == 'logout'){
- session_destroy();
- echo'<center><h3 class="ok">Please Wait .. Redirect after 3 sec ..</h3></center>';
- echo'<meta http-equiv="refresh" content="3;url=session.php">';
- }
- ############################ [End Logout] ##############################################
- ############################ [End Login] ###############################################
- if(isset($_POST['login'])){
- $user = $_POST['user'];
- $pass = md5($_POST['pass']);
- if(empty($user) and empty($pass)){
- echo'Please insert all information and try again';
- }else{
- $query_ad = $connect->query("select * from admin where user = '".$user."' and pass = '".$pass."'");
- if(mysqli_num_rows($query_ad) > 0){
- $fetch_l = $query_ad->fetch_object();
- $g_user = $fetch_l->user;
- $g_pass = md5($fetch_l->pass);
- if($user != $g_user and $pass != $g_pass){
- echo'<h2>Sorry the information incorrect .. Please try again</h2>';
- }else{
- $_SESSION['user'] = $user;
- echo'<center><h3 class="ok">Please Wait .. Redirect after 3 sec ..</h3></center>';
- echo'<meta http-equiv="refresh" content="3;url=session.php">';
- }
- }
- }
- }
- $usern = $_SESSION['user'];
- if(empty($usern)){
- echo'<form action="session.php" method="post">
- Username : <input type="text" name="user"><br>
- Password : <input type="password" name="pass"><br>
- <input type="submit" name="login" value="Login" />
- </form>';
- }else{
- echo 'welcome : '.$usern;
- echo'<br><a href="?type=logout">Logout</a>';
- }
- ############################ [End Login] ###############################################
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement