PHP | Membuat Login Page

1. file koneksi.php

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_koneksi = "localhost";
$database_koneksi = "wave";
$username_koneksi = "root";
$password_koneksi = "";
$koneksi = mysql_pconnect($hostname_koneksi, $username_koneksi, $password_koneksi) or trigger_error(mysql_error(),E_USER_ERROR);
?>

2. file login.php

<?php require_once(‘koneksi.php’); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "’" . $theValue . "’" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "’" . doubleval($theValue) . "’" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "’" . $theValue . "’" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_koneksi, $koneksi);
$query_Con = "SELECT * FROM `user`";
$Con = mysql_query($query_Con, $koneksi) or die(mysql_error());
$row_Con = mysql_fetch_assoc($Con);
$totalRows_Con = mysql_num_rows($Con);
?><?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER[‘PHP_SELF’];
if (isset($_GET[‘accesscheck’])) {
  $_SESSION[‘PrevUrl’] = $_GET[‘accesscheck’];
}

if (isset($_POST[’email’])) {
  $loginUsername=$_POST[’email’];
  $password=$_POST[‘password’];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "sukses.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_koneksi, $koneksi);
 
  $LoginRS__query=sprintf("SELECT email, password FROM `user` WHERE email=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  
  $LoginRS = mysql_query($LoginRS__query, $koneksi) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
   
    //declare two session variables and assign them
    $_SESSION[‘MM_Username’] = $loginUsername;
    $_SESSION[‘MM_UserGroup’] = $loginStrGroup;         

    if (isset($_SESSION[‘PrevUrl’]) && true) {
      $MM_redirectLoginSuccess = $_SESSION[‘PrevUrl’];   
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Geodik | Team Registration</title>
</head>
<style>
input{
    border: 2px solid #55ACEE;
    border-radius: 7px;
    transition: all 0.25s ease-in-out;
    -webkit-transition: all 0.25s ease-in-out;
    -moz-transition: all 0.25s ease-in-out;transition: all 0.25s ease-in-out;
    -webkit-transition: all 0.25s ease-in-out;
    -moz-transition: all 0.25s ease-in-out;
}
input:focus {
    outline: none;
    border-color: #55ACEE;
    box-shadow: 0 0 10px #55ACEE;
    box-shadow: 0 0 5px rgba(0, 0, 255, 1);
    -webkit-box-shadow: 0 0 5px rgba(0, 0, 255, 1);
    -moz-box-shadow: 0 0 5px rgba(0, 0, 255, 1);
}
#login{
    box-shadow: 0px 1px 0px #FFF;
    height: 30px;
    background: none repeat scroll 0% 0% #55ACEE;
border-color: #FFF;
color: #FFF;
}
#login:hover{
background-color: #55ACEE;
background-image: linear-gradient(transparent, rgba(0, 0, 0, 0.15));
border-color: #3B88C3;
}

#login:focus{
background-color: #3B88C3;
background-image: linear-gradient(rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.15));
border-color: #3B88C3;
}
#atas{
border-top-left-radius:10px;
border-top-right-radius:10px;
background:#55ACEE;
width:400px;
height:30px;
color:#FFFFFF;
font-size:20px;
padding-top:10px;
margin-bottom:10px;
text-align:center;
}
#header{
background:#006666;
height:45px;
color:#FFFFFF;
font-size:20px;
margin-bottom:10px;
margin-top:0px;
text-align:center;
}
marquee{
padding-top:5px;
color:#00FF66;
}
#bawah{
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
background:#55ACEE;
width:400px;
height:30px;
}
table{
border-top-left-radius:10px;
border-top-right-radius:10px;
border-bottom-left-radius:10px;
border-bottom-right-radius:10px;
}
body{
background: radial-gradient(circle, #94D2F8, #3A92C8) repeat scroll 0% 0% transparent;
}
.style13 {color: #33FFFF;font-size:14px;}
.style15 {color: #FFFFFF}
</style>
<body style="margin:0px;">

<div align="center">
<div id="header"></div>

<div align="center">
<div id="inner">
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login">

  <table bgcolor="#339999" width="400">
    <tr>
    <td  colspan="3"><div id="atas">TEAM REGRISTRATION</div></td>
    </tr>
  <tr>
    <td width="122"><span class="style13">Email</span></td>
    <td width="8">:</td>
    <td width="254"><label>
      <input size="40" type="email" name="email" id="email" />
    </label></td>
  </tr>
  <tr>
    <td width="122"><span class="style13">Password</span></td>
    <td width="8">:</td>
    <td width="254"><label>
      <input  size="40" type="password" name="password" id="password" />
    </label></td>
  </tr>
      <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right">
    <input type="submit" name="login" id="login" value="Login" />    </td>
  </tr>
    <tr>
    <td  colspan="3"></td>
    </tr>
        <tr>
    <td  colspan="3"></td>
    </tr>
    <tr>
    <td colspan="3"><div id="bawah"><marquee>
      <span class="style15">Selamat bergabung dengan tim pengembang www.geodik.com | Growing With Loving Environment</span>
    </marquee></div></td>
    </tr>
</table>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($Con);
?>

3. file sukses.php

<?php $user=$_SESSION[‘MM_Username’]; echo"<div style=’float:right;display:inline’>Anda sudah login

sebagai $user </div>";?>
<a href="logout.php">logout</a>

4. logout.php

<?php
// *** Logout the current user.
$logoutGoTo = "login.php";
if (!isset($_SESSION)) {
  session_start();
}
$_SESSION[‘MM_Username’] = NULL;
$_SESSION[‘MM_UserGroup’] = NULL;
unset($_SESSION[‘MM_Username’]);
unset($_SESSION[‘MM_UserGroup’]);
if ($logoutGoTo != "") {header("Location: $logoutGoTo");
exit;
}
?>

Leave a Reply