我最近创建了一个非常基本的站点,用户可以在其中登录,然后访问一个他们可以编辑的表。我希望用户只能编辑自己的详细信息,而不能编辑其他人的详细信息,我不知道应该向代码中添加什么才能做到这一点。下面是编辑页面看起来像atm(我知道这样显示密码不是很安全,这只是一个例子)
更新:我不知道我应该添加到删除页面的值,所以它只删除登录用户的详细信息,而不删除任何人的。目前它没有删除任何细节。这是我的注册页面
<?php
// Include config file
require_once "pconfig.php";
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate username
if(empty(trim($_POST["username"]))){
$username_err = "Please enter a username.";
} elseif(!preg_match('/^[a-zA-Z0-9_]+$/', trim($_POST["username"]))){
$username_err = "Username can only contain letters, numbers, and underscores.";
} else{
// Prepare a select statement
$sql = "SELECT id FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = trim($_POST["username"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$username_err = "This username is already taken.";
} else{
$username = trim($_POST["username"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Validate password
if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.";
} elseif(strlen(trim($_POST["password"])) < 6){
$password_err = "Password must have atleast 6 characters.";
} else{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
} else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
}
// Check input errors before inserting in database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
// Prepare an insert statement
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
// Set parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("location: plogin.php");
} else{
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Sign Up</h2>
<p>Please fill this form to create an account.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control <?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $username; ?>">
<span class="invalid-feedback"><?php echo $username_err; ?></span>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $password; ?>">
<span class="invalid-feedback"><?php echo $password_err; ?></span>
</div>
<div class="form-group">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $confirm_password; ?>">
<span class="invalid-feedback"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-secondary ml-2" value="Reset">
</div>
<p>Already have an account? <a href="plogin.php">Login here</a>.</p>
</form>
</div>
这是我的登录页面
<?php
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
header("location: allcontacts.php");
exit;
}
// Include config file
require_once "pconfig.php";
// Define variables and initialize with empty values
$username = $password = "";
$username_err = $password_err = $login_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Check if username is empty
if(empty(trim($_POST["username"]))){
$username_err = "Please enter username.";
} else{
$username = trim($_POST["username"]);
}
// Check if password is empty
if(empty(trim($_POST["password"]))){
$password_err = "Please enter your password.";
} else{
$password = trim($_POST["password"]);
}
// Validate credentials
if(empty($username_err) && empty($password_err)){
// Prepare a select statement
$sql = "SELECT id, username, password FROM users WHERE username = ?";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = $username;
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Store result
mysqli_stmt_store_result($stmt);
// Check if username exists, if yes then verify password
if(mysqli_stmt_num_rows($stmt) == 1){
// Bind result variables
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password);
if(mysqli_stmt_fetch($stmt)){
if(password_verify($password, $hashed_password)){
// Password is correct, so start a new session
session_start();
// Store data in session variables
$_SESSION["loggedin"] = true;
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
// Redirect user to welcome page
header("location: allcontacts.php");
} else{
// Password is not valid, display a generic error message
$login_err = "Invalid username or password.";
}
}
} else{
// Username doesn't exist, display a generic error message
$login_err = "Invalid username or password.";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
mysqli_stmt_close($stmt);
}
}
// Close connection
mysqli_close($link);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Login</h2>
<p>Please fill in your credentials to login.</p>
<?php
if(!empty($login_err)){
echo '<div class="alert alert-danger">' . $login_err . '</div>';
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" class="form-control <?php echo (!empty($username_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $username; ?>">
<span class="invalid-feedback"><?php echo $username_err; ?></span>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control <?php echo (!empty($password_err)) ? 'is-invalid' : ''; ?>">
<span class="invalid-feedback"><?php echo $password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Login">
</div>
<p>Don't have an account? <a href="pregister.php">Sign up now</a>.</p>
</form>
</div>
</body>
</html>
这是我的联系页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Display Contacts</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<title>Display all records from Database</title>
</head>
<body>
<h2>Users</h2>
<table border="2">
<tr>
<td>Sr.No.</td>
<td>Full Name</td>
<td>Password</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php
include "pconfig.php"; // Using database connection file here
$records = mysqli_query($link,"select * from users"); // fetch data from database
while($data = mysqli_fetch_array($records))
{
?>
<tr>
<td><?php echo $data['id']; ?></td>
<td><?php echo $data['username']; ?></td>
<td><?php echo $data['password']; ?></td>
<td><a href="edit.php?id=<?php echo $data['id']; ?>">Edit</a></td>
<td><a href="delete.php?id=<?php echo $data['id']; ?>">Delete</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
最后是我的删除页面
<?php
include "pconfig.php"; // Using database connection file here
$id = $_GET['id']; // get id through query string
if($param_username == "$id") {
$del = mysqli_query($link,"delete from users where id = '$id'"); // delete query
mysqli_close($link); // Close connection
header("location:allcontacts.php"); // redirects to all records page
exit;
}
else
{
echo "Error deleting record"; // display error message if not delete
}
?>
您必须创建一个表,如“用户”,其中包含用户详细信息。现在,当您的用户成功登录时,您必须生成和cookie或会话,这取决于安全存储用户ID的应用程序。然后,当用户想要更改详细信息时,检查ID是否匹配。此外,只显示在字体中登录的用户信息。
开始的一种方法是,在为该表生成每个(HTML)行时,不要回显/输出“编辑”/“删除”链接,除非当前用户的UserId等于该行的UserId。此外,只有当记录的用户ID与当前用户的用户ID相同时,才应运行单击“编辑”/“删除”链接时发生的任何情况。
另一个想法是,当最初加载(超文本标记语言)表以查看记录时,只查询与当前用户相关的行的数据库。然后,在包含编辑/删除链接之前,您不必进行任何进一步的检查。
为了提供更具体的指导/想法,我需要您自己的编码尝试的更详细的问题和示例。
我创建了一个非常基本的网站,用户登录,然后可以访问他们可以编辑的表。我希望用户能够只删除自己的详细信息,没有其他人,我不知道我应该添加到删除页面,所以它只删除登录用户的详细信息,而不删除其他人的。目前它没有删除任何细节。 这是我的注册页面 这是我的登录页面 这是我的联系页面 最后是我的删除页面
记住,使用 tenant2 可以在一些服务调用中更新自己的 TenantId,我们需要在服务器端对它进行安全检测。 与此类似,即使默认情况下,不能看到其他租户的用户,但实际上可以检索和更新他们。 又到了黑客时间。 打开 Chrome 的控制台,并输入: new MultiTenancy.Administration.UserDialog().loadByIdAndOpenDialog(1) 什么?
简介 通过 Cocos Creator 主菜单中 文件->导入项目 的子菜单,可以导入其他编辑器中的项目。目前支持导入的编辑器项目有: Cocos Studio 项目(*.ccs 文件) Cocos Builder 项目(*.ccbproj 文件) 相应的菜单项如图: 操作步骤说明 导入其他编辑器项目的操作步骤如下: 点击相应的菜单,打开文件选择对话框。 选择对应扩展名的文件,即可开始导入。如图:
通过该接口可以编辑指定视频的信息,地址为: http://spark.bokecc.com/api/video/update 需要传递以下参数: 参数 说明 videoid 视频id,不可为空 userid 用户id,不可为空 title 视频标题 tag 视频标签 description 视频描述 categoryid 视频子分类id playurl 视频播放页面地址,如果不编辑播放地址,请勿加
我刚刚开始使用Swagger Editor/OpenAPI 3规范,所以到目前为止还不太好。我已经在本地机器上安装并运行了Swagger Editor v.3.15.2。 这是我到目前为止的yaml: 它显示了这个错误: 我已经确保我对所有缩进使用两个空格。当我从编辑器复制yaml并将其放入记事本时,它看起来很好。我还将其粘贴到另一个编辑器中,注意到它只使用换行符而不是回车。我更新了它以使用两者,