没有空格,顶部位置:session_start():无法发送会话缓存限制器 - 已发送的标头

时间:2016-09-29 15:39:41

标签: php session session-cookies

我阅读了很多讨论,我非常清楚ila函数session_start()必须放在页面的顶部,实际上就是我所做的,但总是出现错误信息。 我也尝试用记事本保存文件,但仍然没有。 下面我们将展示触发错误的简单文件。

错误消息

session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/9/7/f/xxxx.com/httpd.www/ito2/ito-admin/login.php:1) in /customers/9/7/f/xxxx.com/httpd.www/ito2/ito-admin/library.php on line 2

的login.php

  <?php
  include 'library.php';
  if(isset($_SESSION['userid']) && $_SESSION['userid'] != ''){ 
  echo '<script type="text/javascript">window.location = "index.php";      </script>';
 //exit(header('location:index.php'));
 }
 ?>
 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <!-- Meta, title, CSS, favicons, etc. -->
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">

 <title>SicilyTrip</title>

 <!-- Bootstrap -->
 <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<!-- Animate.css -->
<link href="https://colorlib.com/polygon/gentelella/css/animate.min.css" rel="stylesheet">

<!-- Custom Theme Style -->
<link href="css/custom.css" rel="stylesheet">
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#username').focus(); 
$('#login').click(function(){ 
    var username = $('#username'); 
    var password = $('#password'); 
    var login_result = $('.login_result'); 
    login_result.html('caricamento...'); 
    if(username.val() == ''){ 
        username.focus(); 
        login_result.html('<span class="error">Inserisci Username</span>');
        return false;
    }
    if(password.val() == ''){ 
        password.focus();
        login_result.html('<span class="error">Inserisci Password</span>');
        return false;
    }
    if(username.val() != '' && password.val() != ''){ 
        var UrlToPass = 'action=login&username='+username.val()+'&password='+password.val();
        $.ajax({ 
        type : 'POST',
        data : UrlToPass,
        url  : 'checker.php',
        success: function(responseText){ 
            if(responseText == 0){
                login_result.html('<span class="error">Username o Password errati!</span>');
            }
            else if(responseText == 1){
                window.location = 'benvenuto.php';
            }
            else{
                alert('Riscontrato problema SQL');
            }
        }
        });
    }
    return false;
   });
  });
  </script>
  <style type="text/css">
 body{
 margin: 0;
 padding: 0;
 font-family: arial;
 color: #2C2C2C;
 font-size: 14px;
 }
 h1 a{
 color:#2C2C2C;
 text-decoration:none;
 }
 h1 a:hover{
 text-decoration:underline;
 }
.as_wrapper{
 margin: 0 auto;
 width: 1000px;
 }
.mytable{
margin: 0 auto;
padding: 20px;
border:2px dashed #05A9C5;
}
.as_login_heading{
margin:0;
padding:0;
font-weight:bold;
text-align:left;
font-size:18px;
}
.success{
color:#009900;
}
.error{
color:#F33C21;
}
.talign_left{
text-align:left;
}
.as_input{
border:0;
outline:0;
margin:0;
padding:0;
padding:5px;
width:180px;
border:#05A9C5 solid 1px;
}
.as_input:hover{
border:#321363 solid 1px;
}
.as_input.error{
border:#ed1846 solid 1px;
}
.as_button{
background:#05A9C5;
border:none;
outline:none;
margin:0;
padding:0;
color:#FFF;
padding:5px 10px;
font-weight:300;
cursor:pointer;
}
.as_button:hover{
background:#036576;
}
.as_button:active{
background:#a1147d;
}
.login_result{
display:block;
width:100%;
text-align:center;
height:25px;
}
</style>
</head>

<body class="login">
<div>
  <a class="hiddenanchor" id="signup"></a>
  <a class="hiddenanchor" id="signin"></a>

  <div class="login_wrapper">
    <div class="animate form login_form">
      <section class="login_content">
        <form>
          <h1>Login </h1>
          <div class="login_result" id="login_result"></div>
          <div>
            <input type="text" name="username" id="username" class="as_input" placeholder="Username" required="" />
          </div>
          <div>
            <input type="password" name="password" id="password" class="as_input" placeholder="Password" required="" />
          </div>
          <div>
            <input type="submit" name="login" id="login" class="btn btn-default submit" value="Login &raquo;" />
          </div>

          <div class="clearfix"></div>

          <div class="separator">
            <div>
              <h1>xxxxxxx</h1>
              <p>©2016 All Rights Reserved. SicilyTrip</p>
              </div>
            </div>
          </form>
         </section>
       </div>
     </div>
    </div>
  </body>
</html>

library.php

<?php
session_start();
var_dump($_SESSION,$_POST,$_COOKIE,__FILE__,__LINE__); // @RyanVincent
mysql_connect("xxxxxx.com.mysql", "xxxxxx", "xxxxx") or die ("Oops! Server non collegato");
mysql_select_db("xxxxxxxxx") or die ("Oops! Database non connesso");
?>

有人告诉我哪里错了?

这是插入调试行后的答案:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/9/7/f/xxxxxx.com/httpd.www/ito2/ito-admin/login.php:1) in /customers/9/7/f/xxxxxxx.com/httpd.www/ito2/ito-admin/library.php on line 2
array(0) { } array(0) { }
array(1) { ["PHPSESSID"]=> string(26) "rnoue0fq4o0d4kiuf9vqrque85"}
string(68) "/customers/9/7/f/xxxxxx.com/httpd.www/ito2/ito-admin/library.php" int(3)

使用

在线HexDump实用程序的UPDATE响应

http://www.fileformat.info/tool/hexdump.htm

 file name: library.php
 mime type: 

 0000-0010:  3c 3f 70 68-70 0d 0a 73-65 73 73 69-6f 6e 5f 73  <?php..s ession_s
 0000-0020:  74 61 72 74-28 29 3b 0d-0a 76 61 72-5f 64 75 6d  tart();. .var_dum
 0000-0030:  70 28 24 5f-53 45 53 53-49 4f 4e 2c-24 5f 50 4f  p($_SESS ION,$_PO
 0000-0040:  53 54 2c 24-5f 43 4f 4f-4b 49 45 2c-5f 5f 46 49  ST,$_COO KIE,__FI
 0000-0050:  4c 45 5f 5f-2c 5f 5f 4c-49 4e 45 5f-5f 29 3b 0d  LE__,__L INE__);.
 0000-0060:  0a 6d 79 73-71 6c 5f 63-6f 6e 6e 65-63 74 28 22  .mysql_c onnect("
 0000-0070:  73 69 63 69-6c 79 74 72-69 70 2e 63-6f 6d 2e 6d  xxxxxxxx ip.com.m
 0000-0080:  79 73 71 6c-22 2c 20 22-73 69 63 69-6c 79 74 72  ysql",." xxxxxxxx
 0000-0090:  69 70 5f 63-6f 6d 22 2c-20 22 55 7a-5a 33 5a 36  ip_com", ."xxxxxx
 0000-00a0:  53 55 22 29-20 6f 72 20-64 69 65 20-28 22 4f 6f  xx").or. die.("Oo
 0000-00b0:  70 73 21 20-53 65 72 76-65 72 20 6e-6f 6e 20 63  ps!.Serv er.non.c
 0000-00c0:  6f 6c 6c 65-67 61 74 6f-22 29 3b 0d-0a 6d 79 73  ollegato ");..mys
 0000-00d0:  71 6c 5f 73-65 6c 65 63-74 5f 64 62-28 22 73 69  ql_selec t_db("xx
 0000-00e0:  63 69 6c 79-74 72 69 70-5f 63 6f 6d-22 29 20 6f  xxxxxx_com").o
 0000-00f0:  72 20 64 69-65 20 28 22-4f 6f 70 73-21 20 44 61  r.die.(" Oops!.Da
 0000-0100:  74 61 62 61-73 65 20 6e-6f 6e 20 63-6f 6e 6e 65  tabase.n on.conne
 0000-010a:  73 73 6f 22-29 3b 0d 0a-3f 3e                    sso");.. ?>


file name: login.php
mime type: 

0000-0010:  ef bb bf 3c-3f 70 68 70-0d 0a 70 0d-0a 69 6e 63  ...<?php inc
0000-0020:  6c 75 64 65-5f 6f 6e 63-65 20 27 6c-69 62 72 61  lude_onc e.'libra
0000-0030:  72 79 2e 70-68 70 27 3b-0d 0a 69 66-28 69 73 73  ry.php'; ..if(iss
0000-0040:  65 74 28 24-5f 53 45 53-53 49 4f 4e-5b 27 75 73  et($_SES SION['us
0000-0050:  65 72 69 64-27 5d 29 20-26 26 20 24-5f 53 45 53  erid']). &&.$_SES
0000-0060:  53 49 4f 4e-5b 27 75 73-65 72 69 64-27 5d 20 21  SION['us erid'].!
......................................
0000-11a0:  20 20 20 20-20 20 20 20-3c 2f 73 65-63 74 69 6f  ........ </sectio
0000-11b0:  6e 3e 0d 0a-20 20 20 20-20 20 20 20-3c 2f 64 69  n>...... ....</di
0000-11c0:  76 3e 0d 0a-20 20 20 20-20 20 3c 2f-64 69 76 3e  v>...... ..</div>
0000-11d0:  0d 0a 20 20-20 20 3c 2f-64 69 76 3e-0d 0a 20 20  ......</ div>....
0000-11e0:  3c 2f 62 6f-64 79 3e 0d-0a 3c 2f 68-74 6d 6c 3e  </body>. .</html>

问题出在login.php的前几个字符中 感谢@RyanVincent和@DaveChen的建议,我上传了文件,将其转换为ASCII字符,并且在此之前已经出现了这些字符。

谢谢大家...

0 个答案:

没有答案