php重定向循环

Lea*_*cim 0 php redirect

我正在从Lynda.com关注一个php视频教程(它不在线抱歉)并使用以下代码,但是我收到以下错误

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
Run Code Online (Sandbox Code Playgroud)

这可能是我的代码的问题.即代码redirect_to在前10行或15行中有两个,还是在谈论别的东西?

<?php require_once("../../includes/initialize.php"); ?>

<? if(!$session->is_logged_in()){
    redirect_to("login.php"); } ?>

<?php
$logfile = SITE_ROOT.DS.'logs'.DS.'log.txt';
if($_GET['clear'] == 'true') {
 file_put_contents($logfile, '');
 //add the first log entry
 log_action('Logs Cleared', "by User ID {$session->user_id}");
 //redirect to this same page so that the URL won't 
 //have "clear=true" anymore
 redirect_to('logfile.php');
}
?>

<?php include_layout_templates('admin_header.php');?>

<a href="index.php">&laquo; Back</a><br/>

<br/>

<h2>Log File</h2>

<p><a href="logfile.php?clear=true">Clear log file</a></p>

<?php
if (file_exists($logfile) && is_readable($logfile) && 
    $handle = fopen($logfile, 'r')) {//read
    echo "<ul class=\"logentries\">";
    while(!feof($handle)) {
    $entry = fgets($handle);
    if(trim($entry) != "") {
    echo "<li>{$entry}</li>";
    }
    }
    echo "</ul>";
    fclose($handle);
    } else {
    echo "Could not read from {$logfile}.";
    }

?>



//Remember to give your form's submit tag a name="submit" attribute
if (isset($_POST['submit'])) {//Form has been submitted.

$username = trim($_POST['username']);
$password = trim($_POST['password']);

//Check database to see if username/password exist

$found_user = User::authenticate($username, $password);

if ($found_user) {
    $session->login($found_user);
    log_action('Login', "{$found_user->username} loggined in.");
    redirect_to("index.php");
} else {
    //username/password combo was not found in the database
    $message = "Username/password combination incorrect.";
} 
} else {//Form has not been submitted.
    $username = "";
    $password = "";
    }
?>
<?php include_layout_template('admin_header.php'); ?>
        <h2>Staff Login</h2>
        <?php echo output_message($message); ?>

        <form action="login.php" method="post">
            <table>
                <tr>
                    <td>Username:</td>
                    <td>
                        <input type="text" name="username" maxlength="30" value="<?php
                        echo htmlentities($username); ?>" />
                    </td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td>
                        <input type="password" name="password" maxlength="30" value="<?php
                        echo htmlentities($password); ?>" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="submit" name="submit" value="login" />
                    </td>
                </tr>
            </table>
        </form>
        <?php include_layout_template('admin_footer.php'); ?>
Run Code Online (Sandbox Code Playgroud)

Lig*_*ica 5

你有一个无限循环的重定向.

如果你没有登录,"login.php"会重定向到"login.php".如果你没有登录,"login.php"将重定向到"login.php"."login.php"重定向到"login. php"如果你还没有登录."login.php"如果你没有登录则重定向到"login.php"等.

您应该只在当前页面不是"login.php"时才进行重定向; 即从此页面中删除该逻辑.