dongzhi4690 2016-02-05 02:40
浏览 37

PHP Single App / Dual Database - 在Internet Explorer中重定向头后,会话值丢失

Scenario

I am trying to correct an issue with an application that is populating user in a session variable in Internet Explorer using a dual db, single application. I have a unique configuration for a PHP application that is based on the question I asked previously.

https://stackoverflow.com/q/34841867/1691103

I am using a single folder structure that is addressable by the database name. My virtual host name equals the database name being accessed. If I try to access localhost or my computer name I purposely prevent this request since those dbnames do not exist.

http://app      --> loads data from app database
http://app_demo --> loads data from app_demo database

app is the name of the single application directory

Now, when I log in to my application via http://app I can do so in Firefox. Additionally, I can also log into my app via http://app_demo in Firefox. I see the logged in user via the session variable.

Problem

In Internet Explorer my app does not show the logged in user in the Session when accessed via http://app_demo despite being able to do so when accessed via http://app

When I access http://app_demo in Internet Explorer the session is populated right before index.php header redirect but is cleared right after I try to see the value in index.php.

Question

What do I need to do to make login work for both hostnames in IE?

Windows Hosts File

127.0.0.1       app
127.0.0.1       app_demo

Apache Virtual Hosts Definition

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/app"
    ServerName App
    ServerAlias App
    <Directory  "c:/wamp/www/app">
        AllowOverride All
        Options Indexes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/app"
    ServerName app_demo
    ServerAlias app_demo
    <Directory  "c:/wamp/www/app">
          AllowOverride All
        Options Indexes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

index.php

<?php
    session_start();

    if (session_status() === PHP_SESSION_NONE)
    {
        require_once('session.php');
    }
    else if (isset($_SESSION['expire']))
    { 
        $expire = $_SESSION['expire'];
        session_destroy();
        echo $expire;
        echo "<meta http-equiv='refresh' content='0; url=index.php'>";
    }     
?>
<!DOCTYPE html>

session.php

<?php
    session_cache_limiter ('private, must-revalidate');
    session_start();
?>

authenticate.php

 <?php
            require_once('session.php');
            require_once('usermanager.php');

            $username = isset($_POST['username'])? $_POST['username'] : '';
            $password = isset($_POST['password'])? $_POST['password'] : '';


            if ($username == '' or $password == '')
            {
                    header('Location: login.php?err=1');    
                    return;
            }

            $userManager = new UserManager($username, $password);
            if (!$userManager->isValidUserName($username))
            {
                    header('Location: login.php?err=2');
                    return;
            }
            else
            {
                    $confirmed = $userManager->confirmUserNamePassword($username, $password);
                    if (!$confirmed)
                    {     
                        header('Location: login.php?err=3');    
                        return;                     
                    }
                    else
                    {
                        $_SESSION['username'] = $username;
                        $_SESSION['password'] = $password;
                        $_SESSION['userid'] = $userManager->getUserID($username, $password);
                        $_SESSION['userrole'] = $userManager->getUserRole($username, $password);
                        $_SESSION['loggedin'] = true; 
                        $_SESSION['lastnamefirstname'] = $userManager->getLastNameFirstName($username, $password);
                        header('Location: index.php');
                        exit;
                    }
            }

    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?