LoginSignup
1
1

More than 5 years have passed since last update.

IPアドレスが変化してもセッションが切れない様にする

Posted at

Protectorモジュールの一般設定において設定される「セッションを継続する保護ビット」はデフォルト設定値24bitで、192.1680.0 - 255 の範囲で継続してセッションを貼る事を許可しています。

これは、地下鉄等で移動しながらWi-Fi等で接続している場合すぐ違法なセッションとして忌避されてセッションを捨ててしまいます。

この様な場合にはここの値を0にすると継続してログイン状態が保持されます。

ソースは以下の通り。

xoops_trust_path/modules/protector/include/postcheck_functions.php
    // check session hi-jacking
    $ips = explode( '.' ,  @$_SESSION['protector_last_ip'] ) ;
    $protector_last_numip = @$ips[0] * 0x1000000 + @$ips[1] * 0x10000 + @$ips[2] * 0x100 + @$ips[3] ;
    $ips = explode( '.' ,  $_SERVER['REMOTE_ADDR'] ) ;
    $remote_numip = @$ips[0] * 0x1000000 + @$ips[1] * 0x10000 + @$ips[2] * 0x100 + @$ips[3] ;
    $shift = 32 - @$conf['session_fixed_topbit'] ;
    if( $shift < 32 && $shift >= 0 && ! empty( $_SESSION['protector_last_ip'] ) && $protector_last_numip >> $shift != $remote_numip >> $shift ) {
        if( is_object( $xoopsUser ) && count( array_intersect( $xoopsUser->getGroups() , unserialize( $conf['groups_denyipmove'] ) ) ) ) {
            $protector->purge( true ) ;
        }
    }
    $_SESSION['protector_last_ip'] = $_SERVER['REMOTE_ADDR'] ;
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1