【问题标题】:PHP Session Modified on redirect重定向时修改 PHP 会话
【发布时间】:2014-10-30 16:55:15
【问题描述】:

我遇到了一个奇怪的问题,由于某种未知原因,我的 $_SESSION['last_uri'] 变量在 js 重定向上被修改。

这是我们定义 SESSION 变量的地方,目前它显示为 '/training_management':

echo 'SESSION: ' . $_SESSION['last_uri'];

if ( !(preg_match('/login/', $_SERVER['SCRIPT_NAME'])) && !(preg_match('/denied/',       $_SERVER['SCRIPT_NAME'])) ) {
    $_SESSION['last_uri'] = $_SERVER['REQUEST_URI'];

这是我们重定向到新页面的地方:

$("#login_button").click(function() {
    var name = $("input[name$=name]").val();
    var pw = encodeURIComponent($("input[name$=password]").val());
    var query = "func=login&name=" + name + "&password=" + pw;
    ajaxRequest(query, function(data) {
        console.log(data);
        data = data.replace(/(\r\n|\n|\r|\s)/gm, "");
        if (!data || data == 0) {
            failureMsg(_("Incorrect login data."));
        } else {
            window.location.replace("redirect");
        }
    });
});

然后重定向到redirect.php,它显示以下值'/tpl/css/images/ui-icons_222222_256x240.png':

if ( $_SESSION['last_uri'] ) {
    echo $_SESSION['last_uri'];

    //header("Location: " . $_SESSION['last_uri']);
}

会话变量在哪里/如何更改?

这是我的重写规则:

# No www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# No likey .php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

# Some more Security
RewriteEngine On
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ /security [R=301,L]

【问题讨论】:

  • 你在使用url重写吗?看来你重写的有点太多了。
  • 如果你有 mod_rewrite 重写你所有的请求到一个 PHP 脚本,那么点击一个特定的页面很可能会触发一大堆重写:一个用于实际页面,并且每个额外的该页面上的外部资源(例如图像、css、js)。
  • 为帖子添加了重写规则

标签: php session redirect


【解决方案1】:

这可能是发生了什么(见 cmets):

echo 'SESSION: ' . $_SESSION['last_uri']; // display /training_management

if ( !(preg_match('/login/', $_SERVER['SCRIPT_NAME'])) && !(preg_match('/denied/',       $_SERVER['SCRIPT_NAME'])) ) {
    $_SESSION['last_uri'] = $_SERVER['REQUEST_URI'];
    echo 'NEW SESSION: ' . $_SESSION['last_uri']; // display /tpl/css/images/ui-icons_222222_256x240.png
}

其他可能性:

  • /tpl/css/images/ui-icons_222222_256x240.png 未找到重定向到修改会话的 PHP 页面。
  • session_start() 丢失。

【讨论】:

  • redirect.php 不加载包含 $_SESSION['last_uri'] 定义的 header.php
  • 是的,但是您在设置变量之前使用 echo 测试您的变量,因此您的测试可能是错误的。
  • tail session_log last_uri|s:53:"/tpl/css/images/ui-bg_inset-hard_100_fcfdfd_1x100.png"; last_uri|s:43:"/tpl/css/images/ui-icons_222222_256x240.png"; last_uri|s:20:"/training_management"; last_uri|s:20:"/training_management"; last_uri|s:53:"/tpl/css/images/ui-bg_inset-hard_100_fcfdfd_1x100.png"; last_uri|s:43:"/tpl/css/images/ui-icons_222222_256x240.png"; last_uri|s:43:"/tpl/css/images/ui-icons_222222_256x240.png";username|s:13:"matthewharris";logged_in|i:1;auditor_id|s:4:"3042";access_level|s :1:"6";
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-28
  • 2016-10-17
  • 2014-09-09
  • 1970-01-01
  • 2014-08-02
  • 2023-03-20
相关资源
最近更新 更多