私はセッションについてかなり不安です。私はユーザーがログインできるサイトを作っています。あなたがログインしているかどうかにかかわらず、私のすべてのページはheader.htmlを呼び出しています。だから、誰もが、私は次のコードを持って見ることができます私のindex.php
、上:セッション開始のインクルード
**index.php**
<?php
if(!isset($_SESSION['username'])) include('resources/auth/login.php');
else exit(header('Location: home.php'));
if(!isset($_SESSION)) session_start();
if(isset($_GET['todo']) && $_GET['todo'] == 'logout'){
session_unset();
session_destroy();
//echo 'You have been logged out!';
}
?>
<?php include 'resources/includes/header.html';?>
<!-- A lot of code -->
<?php include 'resources/includes/footer.html';?>
セッションコードは、私のヘッダの前に来て、私はhome.php
にリダイレクトしています。代わりに私のヘッダーにそのセッションコードを付けるべきですか?
home.php
<?php
if(!isset($_SESSION)) session_start();
?>
<?php include 'resources/includes/header.html';?>
<!-- A lot of code -->
<?php include 'resources/includes/footer.html';?>
だから私はちょうど私が実際に私の体中のセッションを含めておりますことを、今日以前の考え?私のheader.htmlにはセッションがないのでだから、私はheader.htmlにセッションを持たなければなりませんか?そして、どうすれば最もスマートな方法でそれを行うことができますか?
'場合(ISSET($ _SESSION)!)のsession_start()は、' 'ただのsession_start()'でなければなりません。 –
ご意見ありがとうございます。 header.htmlに追加する必要がありますか? – McDuck4