我正在关注一个来自Lynda.com的php视频教程(不是在线的对不起),并使用了以下代码,但我得到了以下错误
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.这会不会是我的代码有问题。也就是说,代码的前10或15行中有两个redirect_to,或者它在谈论其他东西?
<?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">« 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'); ?>发布于 2011-03-10 19:06:21
你有一个无穷无尽的重定向循环。
如果您没有登录,"login.php“会重定向到"login.php”。如果您没有登录,"login.php“会重定向到"login.php”。如果您没有登录,"login.php“会重定向到"login.php”。如果您没有登录,"login.php“会重定向到"login.php”。等。
您可能应该使重定向仅在当前页面不是“login.php”时发生;即从该页面中删除该逻辑。
发布于 2011-03-10 19:05:55
<? if(!$session->is_logged_in()){
redirect_to("login.php"); } ?>我想这就是你的问题所在。您正在检查登录页面,以查看是否有人已登录。如果没有,您将重定向到您的登录页面,启动一个新的请求,然后它将再次执行检查。
使用登录页面的用户不一定要登录,所以在使用该页面之前,请取消检查某人是否已登录。
发布于 2011-03-10 19:11:48
<?php和1个<? (这也不是一个好主意。我会坚持只使用<?php).https://stackoverflow.com/questions/5258712
复制相似问题