dtntjwkl83750 2014-10-30 16:55
浏览 46
已采纳

PHP会话在重定向上修改

I am having a weird issue where for some unknown reason my $_SESSION['last_uri'] variable is being modified on a js redirect.

This is where we define the SESSION variable, currently it displays as '/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'];

This is where we redirect to a new page:

$("#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(/(
|
||\s)/gm, "");
        if (!data || data == 0) {
            failureMsg(_("Incorrect login data."));
        } else {
            window.location.replace("redirect");
        }
    });
});

This then redirects to redirect.php which shows the following as the value '/tpl/css/images/ui-icons_222222_256x240.png':

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

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

Where / How is the SESSSION variable changed?

HERE are my rewrite rules:

# 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]
  • 写回答

1条回答 默认 最新

  • dongzongxun8491 2014-10-30 16:59
    关注

    This is probably what happend (see comments):

    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
    }
    

    Other possibilities:

    • /tpl/css/images/ui-icons_222222_256x240.png not found redirect to a PHP page that modify the session.
    • session_start() is missing.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题