BTC USD 76,604.1 Gold USD 4,361.32
Time now: Jun 1, 12:00 AM

login php (solve)

arang67

Super Active Member
Messages
6,617
Joined
Apr 27, 2009
Messages
6,617
Reaction score
362
Points
81
problem solved... password xencrypt masa check user time proses login..

PHP:
<?php 
require_once 'database.php'; 

session_start(); 

function signIn() 
{ 
$password = md5(trim($_POST['password']));
$sql = 'SELECT username, user_type FROM users WHERE username = "'.addslashes($_POST['username']).'" '; 
$sql .= 'AND password = "'.$password.'";'; 
dbConnect(); 
$result = runQuery($sql); 

if (mysql_num_rows($result) != 0) 
{ 
$data = mysql_fetch_assoc($result); 
$_SESSION['username'] = stripslashes($data['username']); 
$_SESSION['user_type'] = $data['user_type'];


if ($_SESSION['user_type'] == 'student') 
{ 
header('Location: studentpage.php'); 
} 
else if ($_SESSION['user_type'] == 'staff') 
{ 
header('Location: adminpage.php'); 
} 
} 
else { 
header('Location: login.php?status=SIGN-IN-FAILED'); 

} 
} 

function signOut() 
{ 
session_destroy(); 
header('Location: index2.php'); 
} 

function isSessionValid() 
{ 
if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) { 
signOut(); 
} 

return true; 
} 

if(isset($_POST)){ 
signIn(); 
} 


if (isset($_GET) && $_GET['logout'] == 'true') { 
signOut(); 
} 
?>




salam, saya ada kena buat assignment system library pinjaman buku

bila nak login je fail,padahal user n pass dah masuk betul.

code kat login


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>LMS - Borrowing and Returning Book</title>
<link rel="shortcut icon" href="/_images/favicon1.ico" />
<meta name="author" content="Survs" />
<meta name="keywords" content="borrow books,borrowing" />
<meta name="description" content="Survs is a collaborative tool that enables you to create online surveys with simplicity and elegance." />
<meta name="robots" content="noodp,noydir" />

</head>
<body class="small login">
<div id="wrapper">
<div id="header"><h1><center><img src="image/book.png" alt="" width="417" height="166" /></center></h1>
</div>
<div class="container">
<div id="topcorners"><div class="cleft"></div><div class="cright"></div></div>
<div id="content">

<link rel="stylesheet" type="text/css" href="css\login.css"/>




<form name="f_0_11_1_3_1" method="post" action="authentication.php">
<table class="login" style="margin-left: auto; margin-right: auto;">
<tr>
<td><p class="mtop0 mbottom025"><strong><label for="email">Username or email</label></strong></p><input id="email" tabindex="1" class="inputtext" type="text" name="username" /></td>
</tr>
<tr>
<td><p class="mtop05 mbottom025"><strong><label for="password">Password</label></strong></p><input tabindex="2" class="inputtext" type="password" name="username" id="password" /></td>
</tr>

<tr>

</tr>
<tr>
<td><p class="mtop025 mbottom0"><input type="checkbox" name="remember" id="rememberMe" tabindex="3"/> <label for="rememberMe">Remember me</label></p></td>
</tr>


<tr>
<td style="padding-top: 10px;">
<input class="bprimarypub80" type="submit" tabindex="4" value="Login" />
<input type="hidden" name="action" value="login" />
</td>
</tr>
</table>
</form>


</div>
<div id="bottomcorners"><div class="cleft"></div><div class="cright"></div></div>
</div>
</div>
<div id="footer">
<p>
<a href="http://www.survs.com">Home</a> <span>|</span>
<a href="/privacy/">Privacy Policy</a> <span>|</span>
<a href="/tos/">Terms of Service</a> <span>|</span>
<a href="http://twitter.com/survs">Twitter</a> <span>|</span>
<script type="text/javascript">
Rot13.write('<n uers="znvygb:[email protected]">Pbagnpg</n>');
</script>
</p>
<p>Copyright © 2012 <a href="http://www.enoughpepper.com">Please contact the administrator if cannot login</a></p>
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-194588-3");
pageTracker._trackPageview("/public/Signin");

} catch(err) {}</script>

</body>
</html>

then bila login kat page tulis "Undefined index: logout in C:\myphp\EasyPHP-5.3.9\www\LMS\authentication.php on line 49"

<?php
require_once 'database.php';

session_start();

function signIn()
{
$sql = 'SELECT username, user_type FROM users WHERE username = "'.addslashes($_POST['username']).'" ';
$sql .= 'AND password = "'.addslashes($_POST['password']).'";';
dbConnect();
$result = runQuery($sql);

if (mysql_num_rows($result) != 0)
{
$data = mysql_fetch_assoc($result);
$_SESSION['username'] = stripslashes($data['username']);
$_SESSION['user_type'] = $data['user_type'];

if ($_SESSION['user_type'] == 'student')
{
header('Location: studentpage.php');
}
else if ($_SESSION['user_type'] == 'staff')
{
header('Location: adminpage.php');
}
}
else {
header('Location: login.php?status=SIGN-IN-FAILED');

}
}

function signOut()
{
session_destroy();
header('Location: index2.php');
}

function isSessionValid()
{
if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) {
signOut();
}

return true;
}

if ($_GET['logout'] == 'true') {
signOut();
}
?>

camne eh?..ada salah ke kat function login tu?
 
Last edited:
Code:
<td><p class="mtop05 mbottom025"><strong><label for="password">Password</label></strong></p><input tabindex="2" class="inputtext" type="password" name="[COLOR="Red"]username[/COLOR]" id="password" /></td>

Cuba ang tuko yg merah tu ke password. :)
 
Code:
<td><p class="mtop05 mbottom025"><strong><label for="password">Password</label></strong></p><input tabindex="2" class="inputtext" type="password" name="[COLOR="Red"]username[/COLOR]" id="password" /></td>

Cuba ang tuko yg merah tu ke password. :)

xleh jugak kuar menda ni Undefined index: logout in C:\myphp\EasyPHP-5.3.9\www\LMS\authentication.php on line 49 #:-S
 
Ko bg file biar betul sikit.. Form tu attach ke second file yang ko quote ke ?

Pastu ko quotekan line 49... Aku malas nak kira row 1 per 1
 
<?php
require_once 'database.php';

session_start();

function signIn()
{
$sql = 'SELECT username, user_type FROM users WHERE username = "'.addslashes($_POST['username']).'" ';
$sql .= 'AND password = "'.addslashes($_POST['password']).'";';
dbConnect();
$result = runQuery($sql);

if (mysql_num_rows($result) != 0)*
{
$data = mysql_fetch_assoc($result);
$_SESSION['username'] = stripslashes($data['username']);
$_SESSION['user_type'] = $data['user_type'];

if ($_SESSION['user_type'] == 'student')*
{
header('Location: studentpage.php');
}
else if ($_SESSION['user_type'] == 'staff')*
{
header('Location: adminpage.php');
}
}
else {
header('Location: login.php?status=SIGN-IN-FAILED');

}
}

function signOut()
{
session_destroy();
header('Location: index2.php');
}

function isSessionValid()
{
if (!isset($_SESSION['user_id']) || empty($_SESSION['user_id'])) {
signOut();
}

return true;
}

if(isset($_POST)){
signIn();
}


if (isset($_GET) && $_GET['logout'] == 'true') {
signOut();
}
?>

Cuba replace code ni dgn file authentication.php... Kalau xleh inform blk k..
 
Sekali imbas macam ada 2 kesalahan..

Untuk fail html tu
<td><p class="mtop05 mbottom025"><strong><label for="password">Password</label></strong></p><input tabindex="2" class="inputtext" type="password" name="username" id="password" /></td>
username tukar pada password

Untuk fail php tu
if ($_GET['logout'] == 'true') {
tukar pada
if (isset($_GET['logout']) && $_GET['logout'] == 'true') {
 
Back
Top
Log in Register