Hướng dẫn profile user php - hồ sơ người dùng php

Trong bài viết trước, chúng tôi đã tìm hiểu về việc tạo ra một biểu mẫu đăng nhập đơn giản bằng cách sử dụng PHP và MySQL, và Tạo một biểu mẫu đăng ký đơn giản bằng cách sử dụng PHP và MySQL. Trong bài viết này, chúng tôi sẽ học cách tạo trang hồ sơ người dùng. Người dùng sẽ cần nhập các chi tiết cơ bản để đăng ký và sau đó có thể sử dụng thông tin đăng nhập để đăng nhập. Vì vậy, chúng ta hãy tiến hành các bước dưới đây.Creating a simple login form using PHP and Mysql” and “Creating a simple registration form using PHP and Mysql“. In this article, we are going to learn how to create a user profile page. User will need to input basic details to register himself and after that same credentials can be used to login. So let us proceed with the below steps.

Nội phân Chính showShow

  • 1. Tạo trang chính
  • 2. Đưa ra phong cách cho trang
  • 3. Kết nối với cơ sở dữ liệu
  • 4. Tạo bảng người dùng
  • 5. Mẫu đăng ký xử lý
  • 6. Xử lý mẫu đăng nhập.
  • 7. Tạo phiên người dùng.
  • 8. Tạo trang chào mừng/hồ sơ.
  • 9. Quy trình đăng nhập vào nút và xóa tài khoản.
  • Làm cách nào để xem chi tiết người dùng trong PHP?
  • Làm thế nào tôi có thể thấy tên người dùng chào mừng của tôi trong PHP?
  • Row $ trong PHP là gì?
  • Hồ sơ PHP là gì?

Nội phân chính

  • 1. Tạo trang chính
  • 2. Đưa ra phong cách cho trang
  • 3. Kết nối với cơ sở dữ liệu
  • 4. Tạo bảng người dùng
  • 5. Mẫu đăng ký xử lý
  • 6. Xử lý mẫu đăng nhập.
  • 7. Tạo phiên người dùng.
  • 8. Tạo trang chào mừng/hồ sơ.
  • 9. Quy trình đăng nhập vào nút và xóa tài khoản.
  • Làm cách nào để xem chi tiết người dùng trong PHP?
  • Làm thế nào tôi có thể thấy tên người dùng chào mừng của tôi trong PHP?
  • Row $ trong PHP là gì?
  • Hồ sơ PHP là gì?
  1. Nội phân chính
  2. Tạo trang chính.
  3. Đưa ra phong cách cho trang.
  4. Kết nối với cơ sở dữ liệu.
  5. Tạo bảng người dùng.
  6. Mẫu đăng ký xử lý.
  7. Xử lý mẫu đăng nhập.
  8. Tạo phiên người dùng.
  9. Tạo trang chào mừng/hồ sơ.

1. Tạo trang chính

Quá trình đăng nhập vào và nút Xóa tài khoản.

index.php

 include "logincheck.php"; ?>



 'text/html; charset=UTF-8' http-equiv='Content-Type'/>
 "stylesheet" type="text/css" href="style.css" />
 <span>7</span>topics - Login Demo


"center">
"center-set"> -written by Rahul Ranjan
"signup">
"signup-st">
"center"> $remarks = isset($_GET['remarks']) ? $_GET['remarks'] : ''; if ($remarks==null and $remarks=="") { echo '
Register Here
'
; } if ($remarks=='success') { echo '
Registration Success
'
; } if ($remarks=='failed') { echo '
Registration Failed!, Username exists
'
; } if ($remarks=='error') { echo '
Registration Failed!
Error: '.$_GET['value'].'
'
; } ?>
"reg" action="execute.php" onsubmit="return validateForm()" method="post" id="reg"> "0" align="center" cellpadding="2" cellspacing="0">
class="t-1"> <div align="left" id="tb-name">First&nbsp;Name:div> td> <td width="171"> <input type="text" name="fname" id="tb-box"/> td> tr> <tr> <td class="t-1"><div align="left" id="tb-name">Last&nbsp;Name:div>td> <td><input type="text" name="lname" id="tb-box"/>td> tr> <tr> <td class="t-1"><div align="left" id="tb-name">Email:div>td> <td><input type="text" id="tb-box" name="address" />td> tr> <tr> <td class="t-1"><div align="left" id="tb-name">Username:div>td> <td><input type="text" id="tb-box" name="username" />td> tr> <tr> <td class="t-1"><div align="left" id="tb-name">Password:div>td> <td><input id="tb-box" type="password" name="password" />td> tr> table> <div id="st"><input name="submit" type="submit" value="Submit" id="st-btn"/>div> form> <div id="reg-bottom" class="btmrg">Copyright &copy; 2015 7topics.comdiv> div> div> <div id="login"> <div id="login-st"> <form action="" method="POST" id="signin" id="reg"> php $remarks = isset($_GET['remark_login']) ? $_GET['remark_login'] : ''; if ($remarks==null and $remarks=="") { echo '
Login Here
'
; } if ($remarks=='failed') { echo '
Login Failed!, Invalid Credentials
'
; } ?> "0" align="center" cellpadding="2" cellspacing="0"> "lg-1">
class="tl-1"><div align="left" id="tb-name">Username:div>td> <td><input type="text" id="tb-box" name="username" />td> tr> <tr id="lg-1"> <td class="tl-1"><div align="left" id="tb-name">Password:div>td> <td><input id="tb-box" type="password" name="password" />td> tr> table> <div id="st"><input name="submit" type="submit" value="Login" id="st-btn"/>div> form> <div id="reg-bottom" class="btmrg">Copyright &copy; 2015 7topics.comdiv> div> div> div> div> <div id="footer"><p> Copyright &copy; 2014-2020 7topics.com p>div> body> html>

2. Đưa ra phong cách cho trang

Bây giờ trước tiên chúng ta cần trang chính (index.php). Chúng tôi sẽ tạo hai biểu mẫu I.E ‘Mẫu đăng ký và‘ mẫu đăng nhập. Bạn có thể thấy tập lệnh được sử dụng cho trang chính được đưa ra dưới đây.

style.css

body,li,ul{
 margin:0px auto;
}
body{
 background-color:#3498DB;
 width:100%;
 font-family:sans-serif;
}
header{
 background-color:#fff;
 width:100%;
 height:55px;
 margin:0px;
}
nav{
 width:100%;
 border-top:5px solid #3498DB;
}
nav ul{
 float:left;
 border-left:6px solid #BDC3C7;
 height:50px;
}
nav a{
 text-decoration:none;
 color:#3498DB;
 padding:10px;
 width:auto;
 font-size:30px;
 font-weight:bold;
 border-right:1px solid #BDC3C7;
 font-family:Gabriola;
 height:50px;
}
nav a:hover{
 color:#fff;
 background-color:#3498DB;
 transition:1s;
}
nav li{
 margin:0;
 padding:0;
 list-style:none;
 float:left;
}

#center{
 margin:0px auto;
 width:95%;
}
#center-set{
 float:left;
 width:100%;
 padding-top:1%;
 padding-bottom:0.5%;
 background-color:#A2DED0;
 border-top:5px solid #3498DB;
}
#signup{
 float:left;
 width:50%;
}
#signup-st,#login-st{
 background-color:#22313F;
 margin:50px;
 border-radius:20px;
 -webkit-box-shadow: 3px 3px 4px 0px rgba(0,0,0,0.85);
}
#reg{
 padding-top:10px;
}
#reg-head,#reg-bottom,#reg-head-fail{
 width:100%;
 text-align:center;
 background-color:#fff;
 font-weight:bold;
}
.headrg{
 border-top-left-radius:20px;
 border-top-right-radius:20px;
 padding-top:12px;
 padding-bottom:12px;
 font-size:22px;
 color:#6C7A89;
}
.btmrg{
 padding-top:5px;
 padding-bottom:5px;
 border-bottom-left-radius:20px;
 border-bottom-right-radius:20px;
 font-size:18px;
 color:#22313F;
}
#reg-head-fail{
 color:#D35400;
}
#reg-head:hover{
 color:#3498DB;
 transition:1s;
}
#tb-name{
 float:right;
 font-size:20px;
}
#tb-box{
 height:22px;
 width:200px;
}
#st{
 width:100%;
 text-align:center;
 padding-top:30px;
 padding-bottom:10px;
}
#st-btn{
 text-align:center;
 padding:10px 21px 10px 21px;
 background-color:#3498DB;
 border:none;
 color:#fff;
 cursor:pointer;
 font-size:20px;
 font-weight:bold;
}
#st-btn:hover{
 color:#3498DB;
 background:#fff;
 transition:1s;
}
td.t-1{
 float:left;
 width:44%;
 text-align:right;
 color:#C5EFF7;
}
td.t-2{
 float:right;
 width:55%;
}
#lg-1{
 padding:10px;
 float:left;
 width:95%;
}
.tl-1{
 float:left;
 width:40%;
 padding-right:5%;
 text-align:center;
 color:#C5EFF7;
}
.tl-4{
 font-size:17px;
 font-weight:bold;
 text-align:center;
 color:#FDE3A7;
}
#login{
 float:right;
 width:50%;
}
#login-sg{
 margin-top:20%;
}
#footer{
 background-color:#fff;
 width:100%;
 height:50px;
 margin:0px;
 float:left;
 border-top:5px solid #3498DB;
}
#footer p{
 text-align:center;
 font-size:18px;
 font-weight:bold;
 color:#3498DB;
}

3. Kết nối với cơ sở dữ liệu

Bây giờ chúng tôi sẽ thêm một số phong cách vào biểu mẫu của chúng tôi, để cung cấp cho nó cái nhìn tốt hơn bằng cách sử dụng bảng kiểu bên ngoài ‘style.css.

db.php

 
$mysql_hostname = "localhost";
$mysql_user = "username";
$mysql_password = "password";
$mysql_database = "database";
$con = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database);
?>

4. Tạo bảng người dùng

5. Mẫu đăng ký xử lý

member.sql

CREATE TABLE IF NOT EXISTS `member` (
  `mem_id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(30) NOT NULL,
  `password` varchar(30) NOT NULL,
  `fname` varchar(30) NOT NULL,
  `lname` varchar(30) NOT NULL,
  `address` varchar(100) NOT NULL,
   PRIMARY KEY (`mem_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

5. Mẫu đăng ký xử lý

6. Xử lý mẫu đăng nhập.

execute.php

 
session_start();
include('db.php');
$username=$_POST['username'];
$result = mysqli_query($con,"SELECT * FROM member WHERE username='$username'");
$num_rows = mysqli_num_rows($result);
if ($num_rows) {
 header("location: index.php?remarks=failed"); 
}else {
 $fname=$_POST['fname'];
 $lname=$_POST['lname'];
 $address=$_POST['address'];
 $username=$_POST['username'];
 $password=$_POST['password'];
 if(mysqli_query($con,"INSERT INTO member(fname, lname, address,username, password)VALUES('$fname', '$lname','$address', '$username', '$password')")){ 
 header("location: index.php?remarks=success");
 }else{
  $e=mysqli_error($con);
 header("location: index.php?remarks=error&value=$e");  
 }
}
?>

6. Xử lý mẫu đăng nhập.

7. Tạo phiên người dùng.

logincheck.php


include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
 $username=mysqli_real_escape_string($con,$_POST['username']);
 $password=mysqli_real_escape_string($con,$_POST['password']);
 $result = mysqli_query($con,"SELECT * FROM member");
 $c_rows = mysqli_num_rows($result);
 if ($c_rows!=$username) {
  header("location: index.php?remark_login=failed");
 }
 $sql="SELECT mem_id FROM member WHERE username='$username' and password='$password'";
 $result=mysqli_query($con,$sql);
 $row=mysqli_fetch_array($result);
 $active=$row['active'];
 $count=mysqli_num_rows($result);
 if($count==1) {
  $_SESSION['login_user']=$username;
  header("location: welcome.php");
 }
}
?>

7. Tạo phiên người dùng.

8. Tạo trang chào mừng/hồ sơ.

session.php


include('db.php');
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysqli_query($con,"select username,mem_id from member where username='$user_check'");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$loggedin_session=$row['username'];
$loggedin_id=$row['mem_id'];
if(!isset($loggedin_session) || $loggedin_session==NULL) {
 echo "Go back";
 header("Location: index.php");
}
?>

8. Tạo trang chào mừng/hồ sơ.

9. Quy trình đăng nhập vào nút và xóa tài khoản.

welcome.php


 include('session.php');
?>



 'text/html; charset=UTF-8' http-equiv='Content-Type'/>
 "stylesheet" type="text/css" href="style.css" />
 <span>7</span>topics - Login Demo


"center">
"center-set"> -written by Rahul Ranjan

'center'>Welcome echo $loggedin_session; ?>,

You are now logged in. you can logout by clicking on signout link given below.
"contentbox"> $sql="SELECT * FROM member where mem_id=$loggedin_id"; $result=mysqli_query($con,$sql); ?> while($rows=mysqli_fetch_array($result)){ ?>
"signup">
"signup-st"> "" method="POST" id="signin" id="reg">
"reg-head" class="headrg">Your Profilediv> <table border="0" align="center" cellpadding="2" cellspacing="0"> <tr id="lg-1"> <td class="tl-1"> <div align="left" id="tb-name">Reg id:div> td> <td class="tl-4">php echo $rows['mem_id']; ?>td> tr> <tr id="lg-1"> <td class="tl-1"><div align="left" id="tb-name">Username:div>td> <td class="tl-4">php echo $rows['username']; ?>td> tr> <tr id="lg-1"> <td class="tl-1"><div align="left" id="tb-name">Name:div>td> <td class="tl-4">php echo $rows['fname']; ?> php echo $rows['lname']; ?>td> tr> <tr id="lg-1"> <td class="tl-1"><div align="left" id="tb-name">Email id:div>td> <td class="tl-4">php echo $rows['address']; ?>td> tr> table> <div id="reg-bottom" class="btmrg">Copyright &copy; 2015 7topics.comdiv> form> div> div> <div id="login"> <div id="login-sg"> <div id="st"><a href="logout.php" id="st-btn">Sign Outa>div> <div id="st"><a href="deleteac.php" id="st-btn">Delete Accounta>div> div> div> php // close while loop } ?> div> div> div> br> <div id="footer"><p> Copyright &copy; 2014-2015 7topics.com p>div> body> html>

9. Quy trình đăng nhập vào nút và xóa tài khoản.

Làm cách nào để xem chi tiết người dùng trong PHP?

logout.php


session_start();
if(session_destroy()) {
 header("Location: index.php");
}
?>

Làm thế nào tôi có thể thấy tên người dùng chào mừng của tôi trong PHP?


include('session.php');
?>





"contentbox" > $id=$loggedin_id; $sql="DELETE FROM member WHERE mem_id='$id'"; $result=mysqli_query($con,$sql); if($result){ echo "
"; echo "Account Deleted Sucessfully."; echo " Click here to go back. "; echo "
"
; } elseif(!isset($loggedin_session) || $loggedin_session==NULL) { header("Location: index.php"); } else { echo "Unable to delete Your Account"; } ?>

Row $ trong PHP là gì?

Hồ sơ PHP là gì?

Nội phân chính

Làm cách nào để xem chi tiết người dùng trong PHP?

Làm thế nào tôi có thể thấy tên người dùng chào mừng của tôi trong PHP? php page asks for the desired username, email, and password of the user, and then sends the entered data into the database, once the submit button is clicked. After this, the user is redirected to the index. php page where a welcome message and the username of the logged-in user is displayed.

Làm thế nào tôi có thể thấy tên người dùng chào mừng của tôi trong PHP?

Row $ trong PHP là gì?$_SESSION['username'] = $myusername; $_SESSION['password'] = $mypassword; Because $myusername and $mypassword refer to the username and password sent to the script from the form data.

Row $ trong PHP là gì?

Hồ sơ PHP là gì?Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result set. PHP Version: 5+

Hồ sơ PHP là gì?

Nội phân chínha tool that measures how some code consumes resources at run-time. It enables to find performance bottlenecks and understand the code's behavior. Blackfire Profiler for PHP enables to profile applications during development, test, staging, and production environments.