我的问题不重复,输出发送警告显示标题是从我的代码的第1行发送的
写<?php
。而我正试图在第一行之后开始一个会话。
我一直在尝试加载文件时收到此警告。这是一个登录表单,必须使用cookie。我已经尽力了。中号
警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在/ home /中发送的标头(在/home/stepup/public_html/testing/admin/login.php:1中开始输出)第2行的stepup / public_html / testing / admin / login.php
这是我的代码
<?php
session_start();
require_once "connect.php";
?>
<?php
//Initializing variables
$loginerror= "";
//Server request through post method
if($_SERVER["REQUEST_METHOD"]=="POST")
{
//Fetching data from form
$username = $_POST['username'];
$password = md5($_POST['password']);
//Basic sanitizing
$username = stripslashes($username);
$password = stripslashes($password);
//Checking with database
$sql = "select * from admin where username = '$username' and password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
$count = 0;
$loginerror= "";
while ($line = mysql_fetch_assoc($result))
{
$count++;
$username=$line["username"];
}
if ($count > 0)
{
$_SESSION['loggedIn'] = "TRUE";
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = md5($_POST['password']);
//Redirecting
echo("<script>window.location = 'index.php'</script>");
}
else
{
$_SESSION['loggedIn'] = "false";
$loginerror = "Invalid username or password";
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Free Bootstrap Admin Template : Binary Admin</title>
<!-- BOOTSTRAP STYLES-->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<!-- FONTAWESOME STYLES-->
<link href="assets/css/font-awesome.css" rel="stylesheet" />
<!-- MORRIS CHART STYLES-->
<link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
<!-- CUSTOM STYLES-->
<link href="assets/css/custom.css" rel="stylesheet" />
<!-- GOOGLE FONTS-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-default navbar-cls-top " role="navigation" style="margin-bottom: 0">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">Step Up admin</a>
</div>
</nav>
<!-- /. NAV TOP -->
<nav class="navbar-default navbar-side" role="navigation">
<div class="sidebar-collapse">
<ul class="nav" id="main-menu">
<li class="text-center">
<img src="assets/img/find_user.jpg" class="user-image img-responsive"/>
</li>
</ul>
</div>
</nav>
<!-- /. NAV SIDE -->
<div id="page-wrapper" >
<div id="page-inner">
<div class="row">
<div class="col-md-12">
<h2>Admin Login </h2>
</div>
</div>
<!-- /. ROW -->
<div class="row">
<div class="col-md-12">
<!-- Form Elements -->
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<form role="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method = "POST">
<div class="form-group"><span style="color:#F00;"><?php echo $loginerror;?></span>
<input class="form-control" placeholder="Username" name="username" />
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="Password " />
</div>
<input type="submit" class="btn btn-primary" value="Login" name="submit" />
<div class="panel-heading">
<a href="forgotpassword.php">Forgot Password ?</a>
</div>
</form>
<br />
</div>
</div>
</div>
</div>
<!-- End Form Elements -->
</div>
</div>
</div>
<!-- /. PAGE INNER -->
</div>
<!-- /. PAGE WRAPPER -->
</div>
<!-- /. WRAPPER -->
<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
<!-- JQUERY SCRIPTS -->
<script src="assets/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="assets/js/bootstrap.min.js"></script>
<!-- METISMENU SCRIPTS -->
<script src="assets/js/jquery.metisMenu.js"></script>
<!-- MORRIS CHART SCRIPTS -->
<script src="assets/js/morris/raphael-2.1.0.min.js"></script>
<script src="assets/js/morris/morris.js"></script>
<!-- CUSTOM SCRIPTS -->
<script src="assets/js/custom.js"></script>
</body>
</html>