简体   繁体   English

成功登录后如何将用户重定向到他的个人资料页面?

[英]how to redirect the user to his profile page after succesfully log in?

<?php
include('config.php');

$emailErr = $passwordErr = $log_in_wrong = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$email = $_POST["email"];
$password = $_POST["password"];

if (empty($_POST["email"])) {
  $emailErr = "Your email is required ";
}
if (empty($_POST["password"])) {
  $passwordErr = "Your password is required ";
}
$username_validate=mysqli_query($con, "SELECT password, email FROM users WHERE password = '".$password."' AND  email = '".$email."'");
if(mysqli_num_rows($username_validate)==0){
  $log_in_wrong = "The email or password are incorrect!";
}
if(mysqli_num_rows($username_validate)>=1){
  $log_in_correct = "si";
}
if($log_in_correct == 'si'){
$selectprofile = mysqli_query($con,"SELECT * FROM users");
$row = mysqli_fetch_array($selectprofile);
$slug = $row['slug'];
header("Location: /profile.php?slug=$slug");
}}
 ?>

This is my code and i want to redirect the user to his profile page.这是我的代码,我想将用户重定向到他的个人资料页面。 the user profile page would be profile.php?slug=$slug.用户个人资料页面将是 profile.php?slug=$slug。 the '$slug' is what i use to identify each page. '$slug' 是我用来标识每个页面的。 Maybe my query is wrong or i something like that.也许我的查询是错误的,或者我是这样的。 Thank You!谢谢你!

使用 post 方法并在操作中保留 userprofile.php 文件(userprofile.php 是示例。)首先简单地尝试一下,然后在 url 上附加数据。

The problem was the last query because it took any slug from database, but if you add select slug on the first query, is going to give you the user slug that logged in recently.问题是最后一个查询,因为它从数据库中获取了任何 slug,但是如果您在第一个查询中添加 select slug,将会为您提供最近登录的用户 slug。 Thank to all of you!谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM