dongliuliu0385 2015-11-09 01:30
浏览 110
已采纳

PHP登录太多重定向循环错误

Please help me. I got this error everytime I tried to login. - "This webpage has a redirect loop ERR_TOO_MANY_REDIRECTS" Please help me and I'll appreciate your help very much. thanks.

This is my index.php

<?php
include('login.php'); // Includes Login Script
?>

This is my login.php

<?php

session_start();
$error = "";
if (isset($_POST['submit'])) {
    if (empty($_POST['email']) || empty($_POST['password'])) {
        $error = "Username or Password is invalid";
    } else {
        // Define $username and $password
        $usernameLogin = $_POST['email'];
        $passwordLogin = $_POST['password'];
        // Establishing Connection with Server by passing server_name, user_id and password as a parameter
        $connection = mysql_connect("localhost", "apple", "Apple318992");
        // To protect MySQL injection for Security purpose
        $username = stripslashes($usernameLogin);
        $password = stripslashes($passwordLogin);
        $username = mysql_real_escape_string($username);
        $password = mysql_real_escape_string($password);
        // Selecting Database
        $db = mysql_select_db("TS", $connection);
        // SQL query to fetch information of registerd users and finds user match.
        $query = mysql_query("select * from Users where password='$password' AND email='$usernameLogin'", $connection);
        $rows = mysql_num_rows($query);
        if ($rows == 1) {
            $_SESSION['login_user'] = $usernameLogin; // Initializing Session
        } else {
            $error = "Username or Password is invalid";
        }
    }
}



if (isset($_SESSION["login_user"])) {
    header("Location:timesheets.php");
}
?>

This is my session.php

<?php

include ('DBConnect.php');
session_start(); // Starting Session
// Storing Session
$user_check = $_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql = mysql_query("select email from Users where email='$user_check'", $conn);
$row = mysql_fetch_assoc($ses_sql);
$login_session = $row['email'];
if (!isset($login_session)) {
    mysql_close($conn); // Closing Connection
    header('Location: index.php'); // Redirecting To Home Page
}
?>
  • 写回答

2条回答 默认 最新

  • dongzhiju0324 2015-11-09 01:42
    关注

    In your session.php you have to destroy the session because it might be set still but without that the query can find a existing user?

    To unset sessions do this:

    unset(); for all the session variables unset($_SESSION['login_user']); for a specific session

    Please put that before redirecting to index.php.

    Otherwise I don't know how to help you sorry.

    Also do you have php error / debug enabled? Normally session_start(); should be at very first line in your php file if I am correct, or it throws error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料