当我上传我的网站时出现此错误"警告:session_start():无法发送会话cookie - 已经发送的标头(输出从/storage/ssd3/749/6048749/public_html/index.php开始:1"它在localhost中运行正常,但在远程服务器中运行不正常。这是我的代码:
<?php
$host="localhost";
$uname="id6048749_cman";
$pas="";
$db_name="id6048749_cman";
$tbl_name="admin";
$con = @mysqli_connect("$host","$uname","$pas") or die ("cannot connect");
mysqli_select_db($con , "$db_name") or die ("cannot select db");
?>
<form id="login_form1" class="form-signin" method="post">
<h3 class="form-signin-heading">
<i class="icon-lock"></i> Administrator Login
</h3>
<input type="text" class="input-block-level" id="username" name="username" placeholder="Username" required>
<input type="password" class="input-block-level" id="password" name="password" placeholder="Password" required>
<button data-placement="right" title="Click Here to Sign In" id="signin" name="login" class="btn btn-info" type="submit"><i class="icon-signin icon-large"></i> Sign in</button>
<script type="text/javascript">
$(document).ready(function(){
$('#signin').tooltip('show');
$('#signin').tooltip('hide');
});
</script>
</form>
</br>
<div class="error">
<?php
if (isset($_POST['login'])){
$username=$_POST['username'];
$password=$_POST['password'];
$login_query=mysqli_query($con , "select * from admin where username='$username' and password='$password'");
$count=mysqli_num_rows($login_query);
$row=mysqli_fetch_array($login_query);
if ($count > 0){
session_start();
$_SESSION['id']=$row['admin_id'];
header('location:dashboard.php');
}else{
header('location:index.php');
}
}
?>
</div>
这是index.php
<?php include('header.php'); ?>
<body class="body" id="login">
<div class="container">
<div class="row-fluid">
<div class="span6"><div class="title_index"><?php include('title_index.php'); ?></div></div>
<div class="span6"><div class="pull-right"><?php include('login_admin.php'); ?></div></div>
</div>
<!-- <div class="row-fluid">
<div class="offset2">
<div class="span11"><div class="index-footer"><?php include('link.php'); ?></div></div>
</div>
</div> -->
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<?php include('footer.php'); ?>
</div>
<?php include('script.php'); ?>
</body>
</html>
这是header.php
<!DOCTYPE html>
<html class="no-js">
<head>
<title>Church manager</title>
<meta name="description" content="Church manager">
<meta name="keywords" content="">
<meta charset="UTF-8">
<!-- Bootstrap -->
<!-- <link href="images/logo.png" rel="icon" type="image"> -->
<link href="images/JIL.jpg" rel="icon" type="image">
<link href="bootstrap/css/indexbg.css" rel="stylesheet" media="screen"/>
<link href="bootstrap/css/background.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/font-awesome.css" rel="stylesheet" media="screen">
<link href="bootstrap/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="bootstrap/css/my_style.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/print.css" rel="stylesheet" media="print">
<link href="vendors/easypiechart/jquery.easy-pie-chart.css" rel="stylesheet" media="screen">
<link href="assets/styles.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap.min1.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/sb_admin.css" rel="stylesheet" media="screen">
<!-- HTmL5 shim, for IE6-8 support of HTmL5 elements -->
<!--[if lt IE 9]>
<![endif]-->
<!-- calendar css -->
<script src="bootstrap/js/html5.js"></script>
<link href="vendors/fullcalendar/fullcalendar.css" rel="stylesheet" media="screen">
<script src="vendors/jquery-1.9.1.min.js"></script>
<script src="vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<!-- data table -->
<link href="assets/DT_bootstrap.css" rel="stylesheet" media="screen">
<!-- notification -->
<link href="vendors/jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen">
<!-- wysiwug -->
<link rel="stylesheet" type="text/css" href="vendors/bootstrap-wysihtml5/src/bootstrap-wysihtml5.css"></link>
<script src="vendors/jGrowl/jquery.jgrowl.js"></script>
</head>
<?php include('lib/bcon.php');
dbcon();
?>
编辑:header.php的新版本:
<?php session_start();?>
<html class="no-js">
<head>
<title>Church manager</title>
<meta name="description" content="Church manager">
<meta name="keywords" content="">
<!-- Bootstrap -->
<!-- <link href="images/logo.png" rel="icon" type="image"> -->
<link href="images/JIL.jpg" rel="icon" type="image">
<link href="bootstrap/css/indexbg.css" rel="stylesheet" media="screen"/>
<link href="bootstrap/css/background.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/font-awesome.css" rel="stylesheet" media="screen">
<link href="bootstrap/font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="bootstrap/css/my_style.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/print.css" rel="stylesheet" media="print">
<link href="vendors/easypiechart/jquery.easy-pie-chart.css" rel="stylesheet" media="screen">
<link href="assets/styles.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap.min1.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/sb_admin.css" rel="stylesheet" media="screen">
<!-- HTmL5 shim, for IE6-8 support of HTmL5 elements -->
<!--[if lt IE 9]>
<![endif]-->
<!-- calendar css -->
<script src="bootstrap/js/html5.js"></script>
<link href="vendors/fullcalendar/fullcalendar.css" rel="stylesheet" media="screen">
<script src="vendors/jquery-1.9.1.min.js"></script>
<script src="vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<!-- data table -->
<link href="assets/DT_bootstrap.css" rel="stylesheet" media="screen">
<!-- notification -->
<link href="vendors/jGrowl/jquery.jgrowl.css" rel="stylesheet" media="screen">
<!-- wysiwug -->
<link rel="stylesheet" type="text/css" href="vendors/bootstrap-wysihtml5/src/bootstrap-wysihtml5.css"></link>
<script src="vendors/jGrowl/jquery.jgrowl.js"></script>
</head>
<?php
include('lib/bcon.php');
dbcon();
?>
答案 0 :(得分:-1)
从
中删除此行if ($count > 0)
{
session_start(); // remove session here
$_SESSION['id']=$row['admin_id'];
header('location:dashboard.php');
}
在header.php中添加会话开始行
<?php session_start();?>
这必须是在html开始之前的第一行