如何修改客户区登录php脚本


How to modify login php script for Client Area

我有这个php脚本,重定向用户到特定的页面基于那里的用户名和密码。

一旦你登录并重定向到你的页面,然后离开(例如转到主页),然后再次点击客户端登录返回到你的页面,弹出一条消息说你已经登录,点击这里查看你的页面。我如何让它只是重定向回登录用户的页面?

如果你在理解上有困难,请访问我的网站查看它(用户:tyler pass: tyler获取登录信息)splitlinemedia.com

login。

<?php
    if(!defined("SESSION")){
    session_start();
    define("SESSION", true);
 }
    if(isset($_GET["log_out"])){
    unset($_SESSION["logged_in"]);
    header('refresh: 3; url=login.php');
    echo "You're logged out, and will be redirected in about 3 seconds";
    exit;
 }
 $login = true;
 require "protect.php";
 $logins[0]["user"] = "tyler";
 $logins[0]["pass"] = "tyler";
 $logins[0]["redirect"] = "test.php";
 $logins[1]["user"] = "x";
 $logins[1]["pass"] = "y";
 $logins[1]["redirect"] = "z.php";
  // No need to edit below, except the errors
 if(isset($_POST['submit'])){ //is the form submitted?
   if(empty($_POST['user']) || empty($_POST['pass'])){
     echo "You have to fill out the user name and password!";
     exit;
   } //check for empty user name or password
   $is_logged = false; 
   foreach($logins as $login){
      $user = $_POST;
      if(($user["user"] == $login["user"]) && ($user["pass"] == $login["pass"])) {
         $is_logged = true;
         $_SESSION["logged_in"] = array($login["redirect"], true); 
         header("Location: ".$login["redirect"]);
     exit;
     }
 }
 if(!$is_logged){ echo '<script type="text/javascript">alert("Inncorect username or     password");window.history.go(-1);</script>'; } 
 }
 ?>

protect.php

<?php
if(!defined("SESSION")){
   session_start();
   define("SESSION", true);
}
   if((!isset($_SESSION["logged_in"])) || !$_SESSION["logged_in"][1]){
     if(!isset($login)){
        header("Location: login.php"); //check to see if logged in, otherwise go to the login
    exit;
   }
  } else if (isset($login) || isset($index)){
  echo "Your already logged in!! <a href='login.php?log_out'>Click here</a>, to logout.   Or, go back to your <a href='{$_SESSION['logged_in'][0]}'>page</a>.";
  exit;
 }
?>

然后在test.php页面的顶部

<?php
include("protect.php");
?>

这可能对你有帮助,

<?php
if(!defined("SESSION")){
session_start();
define("SESSION", true);
}
 if((!isset($_SESSION["logged_in"])) || !$_SESSION["logged_in"][1]){
 if(!isset($login)){
 header("Location: login.php"); //check to see if logged in, otherwise go to the login
exit;
}
} else if (isset($login) || isset($index)){
header("Location: " . $_SESSION['logged_in'][0]);
}
?>

protection .php中,只需将echo表示他们已经登录的行替换为标题重定向行,例如:header("Location: ".$_SESSION['logged_in'][0]);