0

我最近创建了一个站点,允许学生登录到一个门户,允许他们上传与不同主题相关的文件。

最近一个学生告诉我,我的网站不能与谷歌浏览器一起工作,他得到的错误是“这个网站有一个重定向循环”。

有人可以在这里看看,看看我在谷歌浏览器的角度做错了什么吗?

PS 该网站适用于所有其他浏览器。

<?php
session_start();

function loggedin()
{
 if (isset($SESSION['myusername']) || isset($_COOKIE['myusername']))
 {
        $loggedin = TRUE;
        return $loggedin;
 }
}

if (loggedin())
{
   header("Location: login_success.php");
}

if(isset($_POST['submit']))
{

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="password"; // Mysql password 
$db_name="data_base_name"; // Database name 
$tbl_name="users"; // 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-8"></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">
  &copy; 2011 Fixnode Computer Services.  All rights reserved.</a>
</footer>
</body>
</html>
4

1 回答 1

1

if在函数语句的表达式中,loggedin()您应该使用$_SESSION['myusername']而不是$SESSION...注意符号后面_的。$

于 2012-10-22T17:30:04.413 回答