次の問題がいくつか発生しています。
基本的に、私はphp/sqlを使用してログインシステムを構築しています。
ルートフォルダ(www)には、cssスタイル、index.php、および関連のないその他のphpファイルが含まれています。
また、このフォルダーには、viewsというフォルダーがあります。「ビュー」には、メインとレイアウトの2つのフォルダーがあります。
レイアウトフォルダには、1行だけのphpファイルの数が含まれています。例えば
<h1> You have logged in! </h1>
(loginconfirm.php)、または
<h1> Log in failed </h1>
(loginfailed.php)。
メインフォルダには、「layout」と「loggedinlayout」の2つのphpファイルが含まれています。
私のインデックスファイルでは、最後に-私はこれを持っています:
include 'views/main/'.$controller.'.php';
ユーザーがログインしたら、$controllerを=layoutから=loggedinlayoutに変更するという考え方です。これにより、新しいレイアウトが読み込まれます。
実際には、インクルードラインを機能させることができるため、これは機能しません。以前使用していたものを使用し続けるだけです。
<?php
// occasional bugs bring up notices, this ignores them
error_reporting(E_ALL ^ E_NOTICE);
// includes the database and cart functions
include('db_function.php');
session_start();
// defaults to index view unless a different view is requested
$view = empty($_GET['view']) ? 'welcome' : $_GET['view'];
function validateUser()
{
session_regenerate_id (); //this is a security measure
$_SESSION['valid'] = 1;
$_SESSION['userid'] = $userid;
}
function isLoggedIn()
{
if(isset($_SESSION['valid']) && $_SESSION['valid'])
return true;
return false;
}
function logout()
{
$_SESSION = array(); //destroy all of the session variables
session_destroy();
}
switch($view) {
case "logout";
logout();
$controller='layout';
//$_SERVER['DOCUMENT_ROOT'];
header('Location:index.php');
break;
case "login";
$user = ($_POST['username']);
$pw = ($_POST['password']);
session_start(); //must call session_start before using any $_SESSION variables
//connect to the database here
db_connect();
$qry = "SELECT userid FROM user WHERE username='$user' AND password='$pw'";
$result = mysql_query($qry);
if(mysql_num_rows($result) < 1) //no such user exists
{
header('Location: ?view=loginfailed');
die();
}
else
{
validateUser(); //sets the session data for this user
}
//redirect to another page or display "login success" message
header('Location: ?view=loginconfirm');
break;
}
//used for layout
// the layout folder is where we put all the different views php files,
// such as the index (first page displayed, even though there is another index)
// or view players for example
if(isset($_SESSION['valid']) && $_SESSION['valid'])
{
$controller = 'loggedinlayout';
}
$controller = 'layout';
// KEEP THIS HERE ALWAYS - THIS IS OUT OF THE CASE/VIEW SECTION
include 'views/main/'.$controller.'.php';
?>
何か提案はありますか?
問題は、ログインすると、「レイアウト」ではなく「loggedinlayout」をレイアウトとして使用して、ログイン確認ページにリダイレクトする必要があることです。