cPanel 修改的 htaccess 文件停止在多个页面上访问会话变量

问题描述 投票:0回答:0

在我的网页中,如果用户登录,那么如果用户移动到同一域下的其他页面,则登录会话变量不可用。登录信息使用 login.php 处理,它重定向到 page2.php。用户信息的session变量在login.php中有,page2.php中没有。 Page2.php 给出以下输出: 在第 2 页找不到用户登录 ID

问题是最近出现的,因为 cPanel 已自动编辑 htaccess 文件以添加以下行:

        <IfModule mime_module>
          AddType application/x-httpd-ea-php74 .php .php7 .phtml
        </IfModule>

如果我从 htaccess 中删除这一行,那么代码运行正常并且 page2.php 给出以下输出: 在第2页找到用户登录id,userid=45

login.php、page.php和htaccess的代码如下所示。 我不想从 htaccess 中删除 cPanel 添加的行,因为这可以再次添加。 cPanel 中的 MultiPHP 管理器显示:ea-php74。 MIME 类型显示: MIME 类型:application/x-httpd-ea-php74,扩展名:.php .php7 .phtml

问题:如何获取 page2.php 上的登录会话变量?

登录.php

        <?php 
        session_start();
        $myUsername = $_POST['FormUsername'];
        $myPassword = md5($_POST['FormPassword']);'
        //Connect to database
        //Find the userid ($myUserId) from database for $myUsername
        $_SESSION['SessionUserId'] = $myUserId;
        header("Location: https://www.example.com/test1/page2.php");
        ?>

page2.php:

        <!DOCTYPE HTML>
        <?php session_start();
        if(isset($_SESSION['SessionUserId'])) {   
           $thisUserId = $_SESSION['SessionUserId'];
           echo "User login id found on page2, userid=$thisUserId  <br/>";
        } else {    
           echo "User login id not found on page2 <br/>";    
        } ?> </html>

Htaccess 文件:

        ErrorDocument 404 /notfound.php
        RewriteCond %{THE_REQUEST} \/index\.(php|html)\ HTTP [NC]
        RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]
        Options 6-Indexes
        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^www\.
        RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
        AuthUserFile /Het/.htpasswd
        # php -- BEGIN cPanel-generated handler, do not edit
        # Set the ea-php74 package as the default PHP programming language.
        <IfModule mime_module>
        AddType application/x-httpd-ea-php74 .php .php7 .phtml
        </IfModule>
        # php -- END cPanel-generated handler, do not edit
php authentication .htaccess session-variables
© www.soinside.com 2019 - 2024. All rights reserved.