我实现了一个在某个目录中托管学校文件的网站,索引页面只是一个登录页面。当我使用谷歌浏览器访问该网站时,它会不断给我一个“重定向循环错误”,但是,如果我使用任何其他浏览器,那么网站正常加载。
我的index.php的网站代码如下,任何建议都表示赞赏。
网站网址为:https://secure.fixnode.ca/
谢谢, Phillip K
<?php
session_start();
function loggedin()
{
if (isset($_SESSION['myusername']) || isset($_COOKIE['myusername']))
{
$loggedin = TRUE;
return $loggedin;
}
}
if (loggedin())
{
header("Location: /login_success.php");
die();
}
if(isset($_POST['submit']))
{
$host="localhost"; // Host name
$username="user"; // Mysql username
$password="password"; // Mysql password
$db_name="database_name"; // Database name
$tbl_name="table_name"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$rememberme=$_POST['rememberme'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);
mysql_close();
// Mysql_num_row is counting table row
if(mysql_num_rows($result) == 1) //user exists
{
if ($rememberme=="on"){
setcookie("myusername", $myusername, time()+7200);
}
elseif ($rememberme==""){
$_SESSION['myusername'] = $myusername;
}
header("Location: /login_success.php");
exit();
}
else {
echo '<div class="alert">Incorrect Username or Password!</div>';
}
}
?>
<?php
// DETECT MOBILE DEVICE
//session_start();
$user_agent=$_SERVER['HTTP_USER_AGENT'];
$iphone = strpos($user_agent,"iPhone");
$android = strpos($user_agent,"Android");
$palmpre = strpos($user_agent,"webOS");
$berry = strpos($user_agent,"BlackBerry");
$ipod = strpos($user_agent,"iPod");
if($_GET['mobile_site'])
{
if (strcmp($_GET['mobile_site'],"false")==0)
$_SESSION['mobile_site']=false;
if (strcmp($_GET['mobile_site'],"true")==0)
$_SESSION['mobile_site']=true;
}
if ($iphone || $android || $palmpre || $ipod || $berry == true)
{
$_SESSION['mobile_device']=true; //
if (isset($_SESSION['mobile_site']))
{
}
else
$_SESSION['mobile_site']=true;
}
else
{
$_SESSION['mobile_site']=false;
$_SESSION['mobile_device']=false;
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Secure Customer Login</title>
<meta charset="UTF-8" />
<script type="application/javascript" src="scripts/bubble_bookmark.js" charset="utf-></script>
<link rel="apple-touch-icon" href="/images/apple-touch-icon.png">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<?php if($_SESSION['mobile_site']==true){ ?>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<?php } ?>
<script type='text/javascript'>
function navigator_Go(url) {
window.location.assign(url);
}
</script>
<script type="text/javascript">
var addToHomeConfig = {
touchIcon: true,
};
</script>
<link rel="stylesheet" type="text/css" href="css/reset.css">
<link rel="stylesheet" type="text/css" href="css/structure.css">
<script>document.createElement('footer');</script>
</head>
<body>
<center><img src="/images/logo.png"></center>
<form class="box login" name="login" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<fieldset class="boxBody">
<label>Username</label>
<input type="email" name="username" tabindex="1" placeholder="Email" required="required">
<label><?php if($_SESSION['mobile_site']==true){ ?><a href="javascript:navigator_Go('recovery.php');" class="rLink" tabindex="5">Forget your password?</a><?php } ?><?php if($_SESSION['mobile_site']==false){ ?><a href="recovery.php" class="rLink" tabindex="5">Forget your password?</a><?php } ?>Password</label>
<input type="password" name="password" tabindex="2" placeholder="Password" required="required">
</fieldset>
<footer>
<label><input type="checkbox" tabindex="3" name="rememberme">Keep me logged in</label>
<input type="submit" name="submit" value="Login" class="btnLogin" tabindex="4">
</footer>
</form>
<footer id="main">
© 2011 Fixnode Computer Services. All rights reserved.</a>
</footer>
</body>
</html>
答案 0 :(得分:0)
登录后使您的函数登录()return true;
并return false
;
未登录时使用if(loggedin() == true)
检查功能
而不是die()
使用exit;
答案 1 :(得分:0)
该子域上的任何URL都会将浏览器发送到重定向循环。例如:
https://secure.fixnode.ca/loops-are-cool
看起来还有别的东西正在进行重定向。也许在.htaccess文件中?