このコードを使用する私は少し問題に答えました。サブフォルダーにリダイレクトしようとすると、登録ユーザーは無視され、index.phpサイトにリダイレクトされます。ルートフォルダにあるが、私はそれをサブフォルダにリダイレクトしようとすると、completilyコードを無視して、index.phpに私をリダイレクトするサイトに私をリダイレクトするときPHPとMySQLのログ記録/リダイレクトに関する問題
// auth.php
class myAuth {
static function checkAuth() {
// detect user by set cookie
// and value which we saved in session
if(!session_id()) session_start();
// check ...
if(
isset($_COOKIE["auth"])
&&
isset($_SESSION["auth"])
&&
$_COOKIE["auth"] == $_SESSION["auth"]
) {
// extend the session and cookie and in mysql as well
self::_setCookieSessionDBTokenValidity();
return true;
} else {
return false;
}
} // chechAuth finish
// this funkcion redirect user
// on main site (index.php)
// na početnu stranicu (index.php)
// use checkAuthWithRedirect if he's not logged in
static function checkAuthWithRedirect() {
if(!self::checkAuth()) {
header('Location:index.php');
}
} // checkAuthWithRedirect finish
static function doLogin() {
// register user
// save data in session
if(
!empty($_POST['user'])
&&
!empty($_POST['pass'])
) {
if(!session_id()) session_start();
// chech and fetch data for user with sended pass
$user = self::_fetchUserWithPassDB();
// if we find user finish login
if($user) {
// strengthen pass a bit
$token = md5(rand(100000,999999));
// save token in session
$_SESSION["auth"] = $token;
// save user in session
$_SESSION["user"] = $user[0]["user"];
// save role in session
$_SESSION["role"] = $user[0]["role"];
// postavi validity i token u cookie, session i bazu
// save validity and token in cookie, session in db
self::_setCookieSessionDBTokenValidity();
// redirect
header("Location:admin.php");
}
else {
echo '<div class="alert alert-danger" role="alert">';
p('<span class="glyphicon glyphicon-exclamation-sign"></span> USER DOES NOT EXIST!');
echo '</div>';
}
}
} // login
コードのこのブロックは正常に動作します。
例:
// redirect
header("Location:test/admin.php");
そしてここadmin.phpサイトの一例である
<?php
// login.php
require_once(__DIR__.'/init.php');
showHTMLHeaderWithTitle('Prijava');
myAuth::checkAuthWithRedirect();
?>
<h1>TEST TEST TEST</h1>
<?php
showHTMLFooter();
?>
あなたはここで404を取得していないと確信していますか? 'test'がスクリプトの実行場所のサブフォルダでない場合は、ルート' header( "Location:/test/admin.php")に戻ります。 exit;または完全なhttp呼び出し 'header("場所:http://www.example.com/test/admin.php "); exit; ' - エラーもチェックします。 –
あなたは '.htaccess'とタグ付けされていますので、書き直しが悪いかどうかわかりません。もう一度、エラーをチェックしたり、ログに何かがあるかどうかを確認してください。私は1つは魔法の答えでポップすることができないためです。がんばろう。私はこれを渡して移動します。 –
.htaccessが私のタグに失敗しました。心配しないで、自分で答えを探している間に質問を投稿しました。ありがとうございました。私は間違いを探すでしょう – Svinjica