は私のすべてのページに追加するファイルが含まれるので、私はログインしていないユーザーからの特定のページ情報を非表示にすることができます。セッションを使用してユーザーのログイン状態が
I私が計画していることを明確にするために十分なコードをコメントして欲しいと思います。
これは、ログイン状態を処理するための4つか5つのファイルを作るのではなく、ユーザー?
すべての入力をいただければ幸いです。ありがとう。
php session_start();
// $layout is the top half of a div that will contain the login status bar (the closing tag is at the bottom of this include file.
$layout='
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
margin:0px;
}
.loginbar {
font-size: 12px;
text-align: right;
padding-top: 5px;
padding-right: 25px;
height: 35px;
width: 100%;
color: #fff;
background-color: #404040;
}
</style>
<div class="loginbar">';
if ($_GET['logout']=='yes'){ // Has the user clicked the log out link?
start_session();
destroy_session();
} else { // No, so carry on..
if !isset($_SESSION['lastname']){ //Is a session already running?
if(!empty($_POST['user']) || !empty($_POST['pass'])) {
#READ $_POST and check $_POST['username'] && $_POST['password'] against the database entries and get the respective 'FirstName' and 'LastName' of the user.
# Set Session vars
} else (empty($_POST['user']) || empty($_POST['pass'])) {
echo $layout;
# DISPLAY LOGIN FORM -> form will resend to this page
}
} else {
echo $layout;
echo "WELCOME ".$FirstName." ".$LastName;
#display LOG OUT link. -> Link will send $_GET['logut='yes'] back to this page.
}
}
?>
</div>
<?php /*
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//In any pages that this inc file is used, I will attempt to block certain bits of information like this:
<?php if ($_SESSION["lastname"]){ ?>
<p style="color:#ff0000;">This is some text that you should only be able to read if you have logged in.</p>
<?php } ?>
//////////////////////////////////////////////////////////////////////////////////////////////////////////
*/
?>
:) offtopicありませんよ。これが起こっているサイトはそれほど複雑ではないので、なぜ私はこのインクルードを望んでいたのですか、いくつかのものを隠すだけです。ありがとう:) – mikenco