我该如何重写这个网址?

时间:2015-12-21 10:09:09

标签: php .htaccess url url-rewriting

这是我的登录脚本。我将用户重定向到/sws/index.php?user=$user,但我想使用.htaccess将其重定向到/sws/index/user/$user

$user变量代表用户的用户名!

我尝试过很多不同的教程来尝试重写URL,但它们没有用!任何人都可以建议一个可以在这里工作的.htaccess脚本吗? 此外,当用户登录时,我希望自动重写URL。

<?php

if (isset($_POST['login'])) {

    include "functions/password.php";

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

    $result = mysqli_query($connect, "SELECT * FROM users0 WHERE email='$email'");
    $row = mysqli_fetch_array($result, MYSQLI_BOTH);

    if (password_verify($password, $row['password'])) {
        session_start();

        $_SESSION["id"] = $row['id'];
        $_SESSION["first_name"] = $row['first_name'];
        $_SESSION["last_name"] = $row['last_name'];
        $_SESSION["email"] = $row['email'];
        $_SESSION["company"] = $row['company'];
        $user = $_SESSION['first_name'] . $_SESSION['last_name'];

        header('Location: index.php?user=' . $user);
    } else {
        header('Location: index.php?error');
    }
}

?>

0 个答案:

没有答案