簡體   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");
}}
 ?>

這是我的代碼,我想將用戶重定向到他的個人資料頁面。 用戶個人資料頁面將是 profile.php?slug=$slug。 '$slug' 是我用來標識每個頁面的。 也許我的查詢是錯誤的,或者我是這樣的。 謝謝你!

使用 post 方法並在操作中保留 userprofile.php 文件(userprofile.php 是示例。)首先簡單地嘗試一下,然后在 url 上附加數據。

問題是最后一個查詢,因為它從數據庫中獲取了任何 slug,但是如果您在第一個查詢中添加 select slug,將會為您提供最近登錄的用戶 slug。 謝謝大家!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM