Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2006, 06:36 PM
Novice Webmaster
 
Join Date: Sep 2006
Location: penang
Posts: 20
Rep Power: 0
slier is on a distinguished road
help Me Check this script

Pada otai2 php tolong aku yer....

ni aku ada buat satu fail...nama fail login.php...berfungsi utk authenticate user yg cuba login ke dalam sistem aku....maksaalhnya setiap kali aku cuba login dgn kombinasi username dann pass yg betul,,aku still masih dapat error message iaitu invalid username/passs...so korang tolong aku yer...

ni fail login.php
<?
//mualakan session
session_start();
//set nama variable
$button=$_POST['submit'];
$uname=$_POST['uname'];
$upass=$_POST['upass'];
//check saamada script diakses secara terus dari url
if((!$button)){
echo"You Need to login first<br>";
echo'<meta http-equiv="refresh" content="5;url=/projek1/index.htm">';
exit();
}


//check samaada form telah diisi dgn complete
if((!$uname) || (!$upass)){
echo"<b>Please Enter Following</b>:<br>";
if ((!$uname)){
echo"Please Enter Your Username<br>";
}
if ((!$upass)){
echo"Please Enter Your Password<br>";
}
exit();
}

$uenname=MD5($uname);
$uenpass=MD5($upass);
$_SESSION['name']=$uenname;
$_SESSION['pass']=$uenpass;

include("top.php");//pilih menu utk succes login dan utk invalid login

//paparkan nama user jika login==valid
if (validate()==true){
$user_sess=$_SESSION['name'];
include("connect.php");
$query=mysql_query("select usernamereal from userdata where username='$user_sess'");
$username=mysql_result($query(0,0));
echo"welcome $username.You Are Now Logged In<br>";

}

else{
echo"Incorrect Username/Password<br>";
}

?>

ni fail top.php
<?
include("validate_user.php");
if(validate()==true)
{
?>

<html>
<body>
<table cellspacing="2" cellpadding="0" border="0">
<tr>
<td><a href="index.htm">Index</a></td>
<td><a href="signup.htm">Signup</a></td>
<td><a href="login.htm"></a>Login</td>
<td><a href="view_user.php">View User</a></td>
<td><a href="post.php"></a>Post</td>
<td><a href="search.php"></a>Search</td>
<td><a href="my_account.php"></a>My Account</td>
<td><a href="logout.php"></a>Logout</td>
</tr>
</table>
<br><br>

<?
}
else
{
?>

<html>
<body>
<table cellspacing="2" cellpadding="0" border="0">
<tr>
<td><a href="index.htm">Index</a>&nbsp;&nbsp;</td>
<td><a href="signup.htm">Signup</a>&nbsp;&nbsp;</td>
<td><a href="login.htm">Login</a>&nbsp;&nbsp;</td>
</tr>
</table><br><br>

<?

}

?>

ni fail validate_user.php
<?
function validate(){
//check samaada session variable dah diset
if($_SESSION['name']){
//extract variable from session
$urname2=$_SESSION['name'];
$urpass2=$_SESSION['pass'];
//connect ke database
include("connect.php");
$query=mysql_query("SELECT * FROM userdata WHERE username='urname2'");
$result=mysql_num_rows($query);
//check samaada user exist
if($result==1){
//check samaada kombinasi usernamse dan pass adalah sama
$query2=mysql_query("SELECT * FROM userdata WHERE username='$urname2' AND password='$urpass2'");
$result2=mysql_num_rows($query2);
if($result2==1){
return true;
}
}
}
}
?>

ni fail connect.php
<?php

$dbh=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("projek1");

?>

sedikit makulmat database:
nama database: projek1
nama table:userdata
field dalam table:
username VARCHAR(200),
password VARCHAR(200),
usernumer INT(5),
usernamereal VARCHAR(50),
ipaddress VARCHAR(50),
avatar VARCHAR(200),
aboutme VARCHAR(200)

so aku harap korang dapat help aku yer...dah berjam dah aku try cari..x jumpa plak...thanks in advance...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-11-2006, 03:50 PM
Krypto's Avatar
New kid on the block
 
Join Date: Apr 2006
Location: KL
Posts: 6
Rep Power: 0
Krypto is on a distinguished road
Send a message via Yahoo to Krypto
$uenname=MD5($uname);

Kenapa perlu md5 username? Adakah username disimpan dlm bentuk encrypted dlm database?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 13-11-2006, 10:10 PM
Novice Webmaster
 
Join Date: Sep 2006
Location: penang
Posts: 20
Rep Power: 0
slier is on a distinguished road
x pa ..problem dah settle...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
sms script zumaidi Website Programming 10 23-02-2007 08:48 AM
check script ni sat..... slier Website Programming 2 16-09-2006 09:55 PM
script nurulmajdi Website Programming 12 16-02-2004 04:03 PM
Help Me With My First Php Script !!!! mya Website Programming 17 24-01-2004 06:12 PM
cgi script Seman Website Programming 6 16-09-2003 05:46 PM


All times are GMT +8. The time now is 12:55 PM. Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61