[英]redirects to the php login page not accessible
重定向到php中的登錄頁面,但登錄成功后無法訪問home.php。 請幫忙
的index.php
<?php
session_start();
require_once 'class.user.php';
$user_login = new USER();
if($user_login->is_logged_in()!="")
{
$user_login->redirect('home.php');
}
if(isset($_POST['btn-login']))
{
$email = trim($_POST['txtemail']);
$upass = trim($_POST['txtupass']);
if($user_login->login($email,$upass))
{
$user_login->redirect('home.php');
}
}
?>
<!DOCTYPE html>
<html>
</html>
home.php
<?php
include("checklogin.php");
check_login();
?>
<!DOCTYPE html>
<html>
</html>
checklogin.php
<?php
function check_login()
{
if(strlen($_SESSION['login'])==0)
{
$host=$_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra="index.php";
$_SESSION["login"]="";
header("Location: http://$host$uri/$extra");
}
}
?>
登錄到home.php之前,將重定向到index.php。 成功登錄后,錯誤率重定向過多
您需要添加session_start();
為您的主頁代碼。 由於會話未在home.php
啟動, home.php
您收到太多重定向錯誤
<?php
session_start();
include("checklogin.php");
check_login();
?>
<!DOCTYPE html>
<html>
</html>
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.