I have made this redirect depending on a condition.
I have a CMS, and I'm developing a mobile version of the site. The main CMS is linked to site_url.com while the mobile version is located on a subdomain m.site_url.com. Below function is an edited logout function in the mentioned CMS.
CodonModule is included as a php include in the index.php of the mobile site. This loads all of the CMS' functions basically.
私が思いついた解決策は、以下で行ったようなリダイレクトを許可しますか、それともサブドメインを見つけてその情報に基づいてリダイレクトを完了するために何か他のものが必要ですか? 現時点では、サブドメインかメイン ドメインかを問わず、スクリプトをトリガーする場所に関係なく、常に else 引数のリンクにリダイレクトされます。したがって、以下のスクリプトを修正し、条件が機能するようにしたいと思います。
Auth::LogOutログアウト プロセスをトリガーします。次に、ユーザーがデスクトップ ページ (else 引数) またはモバイル バージョン (サブドメインにいる場合) にリダイレクトされるように、リダイレクトを追加します。
$die(subdomain)行のすぐ下$subdomainを実行すると、ドメインの名前が出力されます。サブドメインの代わりに出力するべきではありませんかm、それともこのコードを台無しにしてしまったのでしょうか?
class Logout extends CodonModule
{
public function index()
{
$sub_domain = array_shift(explode(".",$_SERVER['HTTP_HOST']));
if($sub_domain == 'm')
{
Auth::LogOut();
header('Location: http://m.site_url.com/index.php');
}
else
{
Auth::LogOut();
header('Location: '.url('/'));
}
}
}