LoginSignup
16
17

More than 5 years have passed since last update.

SimpleAuthでサブドメインをまたぐ

Posted at

hoge.comでログイン画面を出してログインと同時にadmin.hoge.comにリダイレクトしたい。
そしてadmin.hoge.comでもログイン情報を保持したいtips。
調べれば方法は出るものの、また探すのマンドクセので自分用メモ。

原因

SimpleAuthのログイン情報はSessionで持っている。
サブドメインをまたぐときにセッションが切れてしまうので、ログイン情報を維持できない。

対処

app/config/config.php
// (185行目付近)
    /**
     * Cookie settings
     */
    'cookie' => array(
        // Number of seconds before the cookie expires
        // 'expiration'  => 0,
        // Restrict the path that the cookie is available to
        // 'path'        => '/',
        // Restrict the domain that the cookie is available to
        'domain'      => '.hoge.com',   // 変更
        // Only transmit cookies over secure connections
        // 'secure'      => false,
        // Only transmit cookies over HTTP, disabling Javascript access
        // 'http_only'   => false,
    ),

cookieの項目がコメントアウトされていたら(多分デフォルトがそう)、該当部分のみアンコメントしてください。
domain部分にドメインを記述します。今回は.hoge.comと書き換えました。

app/config/session.php
// (42行目付近)
    // cookie domain  (optional, default = '')
    'cookie_domain'     => '.hoge.com', // 14.05.08 変更

ファイルが存在しない場合はcore/config/session.phpをコピーして持ってきて書き換えます。
このように書き換えることで、サブドメイン間でのセッションの維持が可能になります。

session.phpがconfig下に無かったのでしばらくはまってしまった(´@ω@`;)
FuelPHPの構造を理解しきっていないとこういうどうでもいいところでつまります。

16
17
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
16
17