简体   繁体   中英

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. the '$slug' is what i use to identify each page. 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. Thank to all of you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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