Skip to content

Commit

Permalink
thanhnv_58 login and signup
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhnv58 committed May 9, 2015
1 parent b3a4ebb commit d85d073
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
34 changes: 34 additions & 0 deletions login/dangky.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
include "../config.php";
function checkUser( $username ){
global $conn;
$sql = "select email from nguoidung where email = '$username'";
$result = mysqli_query( $conn, $sql );
if( mysqli_num_rows( $result ) > 0 ){
// echo "true";
return true;
}
// echo "false";
return false;
}
if( isset( $_POST['username'] ) and isset( $_POST['password'] ) ){
$check = checkUser( $_POST['username'] );
$username = $_POST['username'];
$password = $_POST['password'];
if( $check == true ){
header("location:index.php");
} else{
if( $password != "" ){
$password = md5( $password );
$sql = "insert into nguoidung set email = '$username', pass = '$password'";
mysqli_query( $conn, $sql );
header("location:../signup/");
} else {
header("location:index.php");
}

}
} else {
header("location:index.php");
}
?>
4 changes: 2 additions & 2 deletions login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<a href="#"><i class="halflings-icon cog"></i></a>
</div>
<h2>Login to your account</h2>
<form class="form-horizontal" action="index.html" method="post">
<form class="form-horizontal" action="dangky.php" method="post">
<fieldset>
<div class="input-prepend" title="Username">
Expand All @@ -74,7 +74,7 @@
<label class="remember" for="remember"><input type="checkbox" id="remember" />Remember me</label>
<div class="button-login">
<button type="submit" class="btn btn-primary">Login</button>
<button type="submit" class="btn btn-primary">Đăng ký</button>
</div>
<div class="clearfix"></div>
</form>
Expand Down
28 changes: 28 additions & 0 deletions signup/dangnhap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
include "../config.php";
// lay password voi username nhap vao
function getPassword( $username ){
global $conn;
$sql = "select pass from nguoidung where email = '$username'";
$result = mysqli_query( $conn, $sql );
if( mysqli_num_rows( $result ) > 0 ){
$row = mysqli_fetch_array( $result, MYSQL_ASSOC );
$pass = $row['pass'];
return $pass;
} else return false;
}
if( isset( $_POST['username'] ) and isset( $_POST['password'] ) ){
$pass = getPassword( $_POST['username'] );
if( $pass == false ){
header("location:index.php");
} else{
echo $pass;
if( md5( $_POST['password'] ) == $pass ){
header("location:../index.php");
} else {
header("location:index.php");
}
}
}

?>
5 changes: 4 additions & 1 deletion signup/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
</head>

<body>
<?php
echo md5("123");
?>
<div class="container-fluid-full">
<div class="row-fluid">

Expand All @@ -56,7 +59,7 @@
<a href="#"><i class="halflings-icon cog"></i></a>
</div>
<h2>Login to your account</h2>
<form class="form-horizontal" action="index.html" method="post">
<form class="form-horizontal" action="dangnhap.php" method="post">
<fieldset>

<div class="input-prepend" title="Username">
Expand Down

0 comments on commit d85d073

Please sign in to comment.