会话问题变得非常烦人。每次我尝试在特定页面上启动会话时,都会出现以下错误:
警告:session_start():无法发送会话缓存限制器 - 已在/ home / uplbcdcn / public_html / CDC / admin_uplbcdc中发送的标头(在/home/uplbcdcn/public_html/CDC/admin_uplbcdc/header.php:57中开始输出)第33行/index.php
警告:无法修改标头信息 - 已经发送的标头(/home/uplbcdcn/public_html/CDC/admin_uplbcdc/header.php:57中的输出)/home/uplbcdcn/public_html/CDC/admin_uplbcdc/index.php第42行
这是代码:header.php
<!DOCTYPE html>
<html>
<head>
<title>UPLB Credit and Development Cooperative</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="../css/bootstrap.css" rel="stylesheet" media="screen">
<link href="../css/bootstrap-responsive.css" rel="stylesheet" media="screen">
<link href="../css/docs.css" rel="stylesheet" media="screen">
<link href="../css/diapo.css" rel="stylesheet" media="screen">
<link href="../css/font-awesome.css" rel="stylesheet" media="screen">
<link rel="stylesheet" type="text/css" href="../css/style.css" />
<link rel="stylesheet" type="text/css" href="../css/DT_bootstrap.css" />
<link rel="stylesheet" type="text/css" media="print" href="../css/print.css" />
<!-- js -->
<script src="../js/jquery-1.7.2.min.js"></script>
<script src="../js/bootstrap.js"></script>
<script src="../js/jquery.hoverdir.js"></script>
<script>
jQuery(document).ready(function() {
$(function(){
$('.pix_diapo').diapo();
});
});
</script>
<noscript>
<style>
.da-thumbs li a div {
top: 0px;
left: -100%;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.da-thumbs li a:hover div{
left: 0px;
}
</style>
</noscript>
<script type="text/javascript" charset="utf-8" language="javascript" src="../js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="../js/DT_bootstrap.js"></script>
<script type='text/javascript' src='../scripts/jquery.easing.1.3.js'></script>
<script type='text/javascript' src='../scripts/jquery.hoverIntent.minified.js'></script>
<script type='text/javascript' src='../scripts/diapo.js'></script>
<!--sa calendar-->
<script type="text/javascript" src="../js/datepicker.js"></script>
<link href="../css/datepicker.css" rel="stylesheet" type="text/css" />
</head>
<?php include('dbcon.php'); ?>
<body>
index.php
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<div class="container">
<div class="margin-top">
<div class="row">
<div class="span12">
<div class="login">
<div class="log_txt">
<p><strong>Please Enter the Details Below..</strong></p>
</div>
<form class="form-horizontal" method="POST">
<div class="control-group">
<label class="control-label" for="inputEmail">Username</label>
<div class="controls">
<input type="text" name="username" id="username" placeholder="Username" required>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" name="password" id="password" placeholder="Password" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button id="login" name="submit" type="submit" class="btn"><i class="icon-signin icon-large"></i> Submit</button>
</div>
</div>
<?php
if (isset($_POST['submit'])){
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
mysqli_select_db($dbcon,$database_dbcon);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($dbcon,$query)or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
if( $num_row > 0 ) {
header('location:dashboard.php');
$_SESSION['id']=$row['user_id'];
}
else{ ?>
<div class="alert alert-danger">Access Denied</div>
<?php
}}
?>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include('footer.php') ?>
答案 0 :(得分:0)
你可以尝试两件事
1)在最顶层写下session_start()。
2)使用标题时使用exit 出口(报头( '位置:dashboard.php'));