gpt4 book ai didi

php - 特定用户表

转载 作者:行者123 更新时间:2023-11-28 23:38:27 25 4
gpt4 key购买 nike

这是一道概念题。现在我有一个注册/登录和一个使用 php 和 mysql 构建的个人资料页面系统,但我有一个问题。

我希望用户能够制作自己的特定待办事项。因此,当他们登录时,他们可以看到自己的待办事项并为自己创建待办事项。只有他们的登录才能访问他们的待办事项。但我不明白如何在 php/mysql 中做到这一点。

这是我的登录页面:

<?php
session_start();
require_once('PhpConsole.phar');
require_once('connection.php');
ob_start();
require('index.php');
$data = ob_get_clean();
ob_end_clean();
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://rawgit.com/marcoceppi/bootstrap-glyphicons/master/css/bootstrap.icon-large.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="lib/sweetalert.css">
<script src="lib/sweetalert-dev.js"></script>
</head>

<body>

<div id="page">

<form method = "post" role = "form" id = "form">
<h1 style = "position:relative; left:60px; font-family: Impact;">Login </h1>
<div class="col-xs-2">
<div class="inner-addon left-addon">
<i class="glyphicon glyphicon-envelope"></i>
<input type="text" class="form-control" id = "email" name = "loginemail" placeholder="Email" />
</div>
</div>
<br>
<div class="col-xs-2">
<div class="inner-addon left-addon">
<img src = "http://i.imgur.com/GqkLI3z.png" id = "imgLock"/>
<input type="text" class="form-control" name = "loginpassword" placeholder="Password" id = "password" />

</div>
</div>

<br>
<br>
<div id = "buttons">
<div class="col-xs-2">
<div class="inner-addon left-addon">
<i class="glyphicon glyphicon-ok-sign" ></i>
<input type = "submit" class="btn btn-info" name = "loginsubmit" id = "submit"/>
</div>
<div>
</div>

</form>
</div>
<?php
if(isset($_POST["loginsubmit"])){

$loginEmail = $_POST["loginemail"];
$loginPassword = $_POST["loginpassword"];
if ($query = mysqli_query($connection, "SELECT * FROM `authe` WHERE Email = '".$loginEmail."' AND Password = '".$loginPassword."' ")) {

$rows = mysqli_num_rows($query);

if($rows>0){
echo "<script> swal('Good job!', 'Sucessfully Authenticated', 'success')</script>";
$_SESSION['email'] = $loginEmail;
$_SESSION['password'] = $loginPassword;
if(true){
// header("Location: http://localhost:8012/phpForm/Profile.php");

if ($queryTwo = mysqli_query($connection, "SELECT Username FROM `authe` WHERE Email = '".$loginEmail."'")) {
$rowsTwo = mysqli_num_rows($queryTwo);
if($rowsTwo>0){
printf($rowsTwo);
while($roww = mysqli_fetch_array($queryTwo))
{
$_SESSION["username"] = $roww['Username'];
}
}
}
echo "<script> window.location.href = 'http://localhost:8012/phpForm/Profile.php' </script>";
}

}
else {
echo "<script>sweetAlert('Oops...', 'Authentication Failed', 'error');</script>";
}
}
}
?>


</body>
</html>

<!-- <br>

<input type = "text" class="form-control" name = "loginemail" style = "width = 20px;" id = "input" placeholder = "Enter Email" required/>
<i class="glyphicon glyphicon-user form-control-feedback"></i>
<br> -->

还有我的个人资料页面:

<?php
session_start();
require_once('PhpConsole.phar');
require_once('connection.php');
ob_start();
require('index.php');
$data = ob_get_clean();
ob_end_clean();

?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://rawgit.com/marcoceppi/bootstrap-glyphicons/master/css/bootstrap.icon-large.css">
<link rel="stylesheet" href="main.css">
<script src="https://code.angularjs.org/1.4.9/angular.js"></script>
<link href='https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:700' rel='stylesheet' type='text/css'>
<script src = "page.js"></script>
<link rel="stylesheet" href="lib/sweetalert.css">
<script src="lib/sweetalert-dev.js"></script>
<style>
#toDoButton {
position: relative;
color: rgba(255,255,255,1);
text-decoration: none;
background-color: rgba(219,87,5,1);
font-family: 'Yanone Kaffeesatz';
font-weight: 700;
right:550px;
bottom:70px;
font-size: 3em;
display: block;
padding: 4px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0px 9px 0px rgba(219,31,5,1), 0px 9px 25px rgba(0,0,0,.7);
-moz-box-shadow: 0px 9px 0px rgba(219,31,5,1), 0px 9px 25px rgba(0,0,0,.7);
box-shadow: 0px 9px 0px rgba(219,31,5,1), 0px 9px 25px rgba(0,0,0,.7);
margin: 100px auto;
width: 160px;
text-align: center;

-webkit-transition: all .1s ease;
-moz-transition: all .1s ease;
-ms-transition: all .1s ease;
-o-transition: all .1s ease;
transition: all .1s ease;
}

#toDoButton:active {
-webkit-box-shadow: 0px 3px 0px rgba(219,31,5,1), 0px 3px 6px rgba(0,0,0,.9);
-moz-box-shadow: 0px 3px 0px rgba(219,31,5,1), 0px 3px 6px rgba(0,0,0,.9);
box-shadow: 0px 3px 0px rgba(219,31,5,1), 0px 3px 6px rgba(0,0,0,.9);
}

</style>
</head>

<body>

<div id="page" ng-app = "pageApp" ng-controller="pageController">
<h1>Welcome <?php echo $_SESSION['username']; ?></h1>
<h5>Here is one cool feauture. Type in the box :)</h5>
<div class = "coolFeauture" id = "CoolFeauture1">
<input type = "text" ng-model = "CoolFeauture"/>
<div ng-bind = "CoolFeauture"></div>
</div>
<div class = "todoMain">
<h4>Click on the button for a TODO App! Check it out!</h4>
<a href="javascript:void(0);" id = "toDoButton">Todo</a>
</div>
</div>
<?php
?>


</body>
</html>

<!-- <br>

<input type = "text" class="form-control" name = "loginemail" style = "width = 20px;" id = "input" placeholder = "Enter Email" required/>
<i class="glyphicon glyphicon-user form-control-feedback"></i>
<br> -->

最佳答案

既然是概念题,而且你提到登录/注册系统已经做好了,你需要做的是:

  • 记录他们保存一个独特的$_SESSION['id'] , 或可过期的唯一 key 。
    • 此外,您可以保存 cookie 以识别他们的帐户

todo.php页:

  • 通过检查 $_SESSION['id'] 确保他们已登录(如果已设置,则重定向到某处或弹出消息)。
  • 通过 SELECT * FROM todo WHERE user='id' 查询他们当前存储的 TODO
  • 显示<textarea>或类似于存储新的 TODO(您可以通过 POST 到同一页面)。
  • 如果页面得到 POST要求:
    • 通过 INSERT INTO todo('id', 'sanitized $_POST["text"]') 存储新的 TODO

此外,请始终确保在执行任何这些查询之前清理变量。

关于php - 特定用户表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35110210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com