PHP形式session_start():无法发送会话缓存限制器 [英] PHP form session_start(): Cannot send session cache limiter

查看:71
本文介绍了PHP形式session_start():无法发送会话缓存限制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误消息:session_start():无法发送会话缓存限制器-标头已发送(输出从/home/page4_insertdata.php:30开始) /home/page4_insertdata.php,第31行"

I am getting the error message ": session_start(): Cannot send session cache limiter - headers already sent (output started at /home/page4_insertdata.php:30) in /home/page4_insertdata.php on line 31"

我检查了空格/空白,找不到任何内容,不确定在30/31行之前向浏览器输出什么.

I have checked for blank/white space and I can't find any, not sure what is outputting to the browser before lines 30/31.

PHP

<?php
    // Turn off all error reporting 
    error_reporting(0);
    // Report simple running errors 
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    // Reporting E_NOTICE can be good too (to report uninitialized 
    // variables or catch variable name misspellings ...) 
    error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    // Report all errors except E_NOTICE 
    // This is the default value set in php.ini 
    error_reporting(E_ALL ^ E_NOTICE);
    // Report all PHP errors (see changelog) 
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    // Report all PHP errors 
    error_reporting(-1);
    // Same as error_reporting(E_ALL); 
    ini_set('error_reporting', E_ALL);
    ?>
<html>
    <head>
        <title>Page Form</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <div class="container">
            <div class="main">
                <h2>PHP Form</h2><hr/>
                <?php

    session_start();

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

        if (!empty($_SESSION['post'])){

            if (empty($_POST['address1'])|| empty($_POST['city'])|| empty($_POST['pin'])|| empty($_POST['state'])){
                //Setting error for page 3
                $_SESSION['error_page3'] = "Mandatory field(s) are missing, Please fill it again";
                header("location: page3_form.php");
                //redirecting to third page
            } else {
                foreach ($_POST as $key => $value) {
                    $_SESSION['post'][$key] = $value;
                }

                //function to extract array
                extract($_SESSION['post']);
                //Storing values in database
                $connection = mysql_connect("localhost","my_user","my_password","my_db");
                $db = mysql_select_db("user_details", $connection);
                $query = mysql_query("insert into detail (name,email,contact,password,religion,nationality,gender,qualification,experience,address1,address2,city,pin,state) values('$name','$email','$contact','$password','$religion','$nationality','$gender','$qualification','$experience','$address1','$address2','$city','$pin','$state')", $connection);

                if ($query) {
                    echo '<p><span id="success">Form Submitted successfully..!!</span></p>';
                } else {
                    echo '<p><span>Form Submission Failed..!!</span></p>';
                }

                //destroying session
                unset($_SESSION['post']);
            }

        } else {
            header("location: page1_form.php");
            //redirecting to first page
        }

    } else {
        header("location: page1_form.php");
        //redirecting to first page
    }

    ?>
            </div>
        </div>
    </body>
</html>

推荐答案

始终尝试使用文件顶部的session_start()函数.

Always try to use the session_start() function at the top of the file.

<?php
session_start();
// Turn off all error reporting 
error_reporting(0);

,然后从其他任何地方删除它,那么它将正常工作.

and remove the same from every where else, then it will work fine.

这篇关于PHP形式session_start():无法发送会话缓存限制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆