0

Выдает ошибку:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at D:\OSPanel\domains\tAKNYT\index.php:4) in D:\OSPanel\domains\tAKNYT\blocks\header.php on line 3

Вот код header:

<?php 
    session_start();
?>
<!DOCTYPE html>
<html>
<head>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            "use strict";
            //================ Проверка email ==================

            //регулярное выражение для проверки email
            var pattern = /^[a-z0-9][a-z0-9\._-]*[a-z0-9]*@([a-z0-9]+([a-z0-9-]*[a-z0-9]+)*\.)+[a-z]+/i;
            var mail = $('input[name=email]');

            mail.blur(function(){
                if(mail.val() != ''){

                    // Проверяем, если введенный email соответствует регулярному выражению
                    if(mail.val().search(pattern) == 0){
                        // Убираем сообщение об ошибке
                        $('#valid_email_message').text('');

                        //Активируем кнопку отправки
                        $('input[type=submit]').attr('disabled', false);
                    }else{
                        //Выводим сообщение об ошибке
                        $('#valid_email_message').text('Не правильный Email');

                        // Дезактивируем кнопку отправки
                        $('input[type=submit]').attr('disabled', true);
                    }
                }else{
                    $('#valid_email_message').text('Введите Ваш email');
                }
            });

            //================ Проверка длины пароля ==================
            var password = $('input[name=password]');

            password.blur(function(){
                if(password.val() != ''){

                    //Если длина введенного пароля меньше шести символов, то выводим сообщение об ошибке
                    if(password.val().length < 6){
                        //Выводим сообщение об ошибке
                        $('#valid_password_message').text('Минимальная длина пароля 6 символов');

                        // Дезактивируем кнопку отправки
                        $('input[type=submit]').attr('disabled', true);

                    }else{
                        // Убираем сообщение об ошибке
                        $('#valid_password_message').text('');

                        //Активируем кнопку отправки
                        $('input[type=submit]').attr('disabled', false);
                    }
                }else{
                    $('#valid_password_message').text('Введите пароль');
                }
            });
        });
    </script>
</head>
<header>
    <div id="logo">
        <a href="/" title="Перейти на главную">
            <span>Н</span>овости
        </a>
    </div>
<div id="auth_block">   
<?php 
        //Проверяем авторизован ли пользователь
        if(!isset($_SESSION['email']) && !isset($_SESSION['password'])){
        // если нет, то выводим блок с ссылками на страницу регистрации и авторизации
?>
        <div id="regAuth">
        <a href="/signup.php">Регистрация</a> | <a href="login.php">Авторизация</a>     
        </div>
<?php
        }else{
?>          
        <div id="link_logout">
            <a href="/logout.php">Выход</a>
        </div>  
    <?php
        }
    ?>
</div>
    <div class="clear"></div>

</header>
</html>

А вот код index:

<!DOCTYPE html>
<html>
<head>
<?php
    $title = "tAKNYT";
    require_once "blocks/head.php";
?>
</head>
<body>
    <?php require_once "blocks/header.php" ?>   
    <div id="wrapper">
            <div id="bigArticle">
                <img src="/img/articles/1.jpg" alt="Статья 1" title="Статья 1">
                <h2>Статья 1</h2>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
                <a href="/article.php">
                    <div class="more">Далее</div>
                </a>
            </div>
            <div class="clear"><br></div>
            <div class="article">
                <img src="/img/articles/2.jpg" alt="Статья 1" title="Статья 1">
                <h2>Статья 1</h2>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
                <a href="/article.php">
                    <div class="more">Далее</div>
                </a>
            </div>
            <div class="article">
                <img src="/img/articles/3.jpg" alt="Статья 1" title="Статья 1">
                <h2>Статья 1</h2>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. </p>
                <a href="/article.php">
                    <div class="more">Далее</div>
                </a>
            </div>
    </div>

    <?php require_once "blocks/footer.php" ?>

</body> 
</html>
1

1 ответ 1

0

session_start(); перенесите из header.php в index.php

Из мануала :

Замечание: Для использования сессий на основе cookie, функция session_start() должна быть вызвана перед выводом чего бы то ни было в браузер.

http://php.net/manual/ru/function.session-start.php

1
  • Огромное спасибо, проблема решена.
    – AKNYT
    18 сен 2017 в 4:12

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.