błąd headów w php?

0

cześć wszystkim
robię stronę i mam zgrzyt z trzema błędami. Kompletnie nie wiem o co chodzi. Wiem, że błąd dotyczy headów i przesyłania w nich informacji, ale nie rozumiem co robię źle. Proszę o pomoc. Błąd który występuje:

Warning: Cannot modify header information - headers already sent by (output started at /wp-content/themes/instrukcje/standar_show/layout_header.php:9) in /wp-content/themes/instrukcje/standar_show/read_template.php on line 55

index -> strona w której wybieram element z comboboxa i klikam na przycisk żeby aktywować comboboxa. Tu pojawia się komunikat, który podałem wyżej

<?php
session_start();


if(!($_SESSION['log'])){
header("Location: /wp-content/themes/instrukcje/standar_show/index.php?error=4");
exit;
}

?>
<?php
include_once 'config/core.php';
 
include_once 'config/database.php';
include_once 'objects/instruction.php';
include_once 'objects/category.php';
 
$database = new Database();
$db = $database->getConnection();
 
$instruction = new Instruction($db);
$category = new Category($db);
 
$page_title = "Read Instruction";
include_once "layout_header.php";
 
$stmt = $instruction->readAll($from_record_num, $records_per_page);
 
$page_url = "index.php?";
 
$total_rows=$instruction->countAll();
 
include_once "read_template.php";
 
include_once "layout_footer.php";
?>

layout_header


<!DOCTYPE html>
<html lang="en">
<head>
 
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 
**<title><?php echo $page_title;?></title>**PIERWSZY BŁĄD
 
    <!-- Latest compiled and minified Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  
    <!-- our custom CSS -->
    <link rel="stylesheet" href="libs/css/custom.css" />
  
</head>
<body>
 
    <!-- container -->
    <div class="container">
 
        <?php
        // show page header
        echo "<div class='page-header'>
                <h1>{$page_title}</h1>
            </div>";
        ?>

read_template


<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<?php

echo "<div class='right-button-margin'>";
    echo "<a href='../standar.php' class='btn btn-primary pull-right'>";
    echo "<span class='glyphicon glyphicon'></span> Back Menu	";
    echo "</a>";
echo "</div>";

if($total_rows>0){
	        echo "<div class='page-header'>
                <h4>Last 5 instructions</h4>
            </div>";
 echo "<div>";
    echo "<table class='table table-hover table-responsive table-bordered'>";
        echo "<tr>";
            echo "<th>Name</th>";
            echo "<th>Date</th>";
			echo "<th>Actions</th>";
        echo "</tr>";
 
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
 
            extract($row);
            echo "<tr>";
			echo "<td>{$name}</td>";
			echo "<td>{$modified}</td>";
		
                echo "<td>";
 
                    echo "<a href='read_one.php?id={$id}' class='btn btn-primary left-margin'>";
                        echo "<span class='glyphicon glyphicon-list'></span> Read";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";

			}
		echo "</table>";
	echo "</div>";	

 }
// tell the user there are no users
else{
    echo "<div class='alert alert-danger'>No instructions found.</div>";
}
?>	
<?php
if($_POST){
	
	if(isset($_POST['cat_id_select'])){
	$_SESSION['cat_id_select'] = $_POST['cat_id_select'];	
	$_POST['cat_id_select'] = null;	
	**header('Location: /wp-content/themes/instrukcje/standar_show/showAll_category.php');**DRUGI BŁĄD
	}
	
	if(isset($_POST['subcat_id_select'])){
	$_SESSION['subcat_id_select'] = $_POST['subcat_id_select'];	
	$_POST['subcat_id_select'] = null;	
	**header('Location: /wp-content/themes/instrukcje/standar_show/showAll_subcategory.php')**;TRZECI BŁĄD
	}
}


	        echo "<div class='page-header'>
                <h4>Category/subcategory filter</h4>
            </div>";
?>
<div>
    <table class='table table-hover table-responsive table-bordered'>
 	<form method="post">
            <tr>
                <td>
				<select id="category-select" name="cat_id_select" class="clear-right">
					<option value="0" >Select a category</option>
					<option value="1">Szkolenia</option>

				</select>
				</td>
            	<td> 
                <button type="submit" class="btn btn-primary">Show All Category</button>
            	</td>
            	</tr>
		</form>
		<form method="post">
		<tr>
			<td>
				<select id="subcategory-select" name="subcat_id_select" class="clear-right">
				<option value="0">Select a subcategory</option>
        	<optgroup label="Programy">
        		<option value="1">profilaktyczny</option>
 
				</select>
			</td>
			<td>
				<button type="submit" class="btn btn-primary">Show All Subcategory</button>
			</td>
			
		</tr>
		</form>
</table>
</div>

0

Nie mam pojęcia co chcesz w ten sposób zrobić...

Ale przenieś tą instrukcje na góre kodu tak by została wywołana zanim zostaną wysłane nagłówki. Takie rzeczy robi się raczej w theme.php albo tworzy plugin. Nie w środku widoku... :(

0

Błąd występuje bo przed header'em wysyłasz dane.
header powinien zostać umieszczony przed jakimikolwiek danymi wyjściowymi.

BŁĘDNIE

Hello World!
<?php
header("Location: http://example.com/");
?>

POPRAWNIE

<?php
header("Location: http://example.com/");
?>
Hello World!
0

przerzuciłem heady, ale ciągle pokazuje się ten sam problem.

layout_header

 <?php
        // show page header
        echo "<div class='page-header'>
                <h1>{$page_title}</h1>
            </div>";
        ?>
<!DOCTYPE html>
<html lang="en">
	
<head>
 
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
 

    <!-- Latest compiled and minified Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  
    <!-- our custom CSS -->
    <link rel="stylesheet" href="libs/css/custom.css" />
  
</head>
<body>
 
    <!-- container -->
    <div class="container">
		
  <title><?php echo $page_title;?></title>

read_template

<?php
if($_POST){
	
	if(isset($_POST['cat_id_select'])){
	$_SESSION['cat_id_select'] = $_POST['cat_id_select'];	
	$_POST['cat_id_select'] = null;	
	header('Location: /wp-content/themes/instrukcje/standar_show/showAll_category.php');
	}
	
	if(isset($_POST['subcat_id_select'])){
	$_SESSION['subcat_id_select'] = $_POST['subcat_id_select'];	
	$_POST['subcat_id_select'] = null;	
	header('Location: /wp-content/themes/instrukcje/standar_show/showAll_subcategory.php');
	}
}


	        echo "<div class='page-header'>
                <h4>Category/subcategory filter</h4>
            </div>";
?>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<?php

echo "<div class='right-button-margin'>";
    echo "<a href='../standar.php' class='btn btn-primary pull-right'>";
    echo "<span class='glyphicon glyphicon'></span> Back Menu	";
    echo "</a>";
echo "</div>";

if($total_rows>0){
	        echo "<div class='page-header'>
                <h4>Last 5 instructions</h4>
            </div>";
 echo "<div>";
    echo "<table class='table table-hover table-responsive table-bordered'>";
        echo "<tr>";
            echo "<th>Name</th>";
            echo "<th>Date</th>";
			echo "<th>Actions</th>";
        echo "</tr>";
 
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
 
            extract($row);
            echo "<tr>";
			echo "<td>{$name}</td>";
			echo "<td>{$modified}</td>";
		
                echo "<td>";
 
                    echo "<a href='read_one.php?id={$id}' class='btn btn-primary left-margin'>";
                        echo "<span class='glyphicon glyphicon-list'></span> Czytaj";
                    echo "</a>";
			
                echo "</td>";
            echo "</tr>";

			}
		echo "</table>";
	echo "</div>";	

 }
// tell the user there are no users
else{
    echo "<div class='alert alert-danger'>No instructions found.</div>";
}
?>	

<div>
    <table class='table table-hover table-responsive table-bordered'>
 	<form method="post">
            <tr>
                <td>
				<select id="category-select" name="cat_id_select" class="clear-right">
					<option value="0" >Select a category</option>
					<option value="1">Programy i profilaktyka</option>

				</select>
				</td>
            	<td> 
                <button type="submit" class="btn btn-primary">Show All Category</button>
            	</td>
            	</tr>
		</form>
		<form method="post">
		<tr>
			<td>
				<select id="subcategory-select" name="subcat_id_select" class="clear-right">
				<option value="0">Select a subcategory</option>
        	<optgroup label="Programy">
        		<option value="1">Programy</option>


				</select>
			</td>
			<td>
				<button type="submit" class="btn btn-primary">Show All Subcategory</button>
			</td>
			
		</tr>
		</form>
</table>
</div>
0

layout_header.php masz PRZED read_template.php?

0

tak,
tak to dam przed to cała strona mi się sypie.

0

zmieniam, ale jak daję to wyżej to się cała strona sypie.

0

W pliku index.php zmieniam kolejność wyświetlania pierwszy jest read_template.php i a potem layout_header.php.
Link pierwszy przedstawia stronę bez przedstawienia z pierwotnym błędem, link 2 przedstawia gdy ustawiam read_template.php jako pierwszy plik do wycztania
link 1

link 2

index.php

<?php
session_start();


if(!($_SESSION['log'])){
header("Location: index.php?error=4");
exit;
}

?>
<?php
include_once 'config/core.php';
include_once 'config/database.php';
include_once 'objects/instruction.php';
include_once 'objects/category.php';
 
$database = new Database();
$db = $database->getConnection();
 
$instruction = new Instruction($db);
$category = new Category($db);
 
include_once "read_template.php";
 
$page_title = "Read Instruction";
include_once "layout_header.php";
 
$stmt = $instruction->readAll($from_record_num, $records_per_page);
 
$page_url = "index.php?";
 
$total_rows=$instruction->countAll();
 
include_once "layout_footer.php";
?>

zmieniłem również miejsce z headem. Ciągle jest ten sam problem :(

plik o nazwie read_template.php

<?php

if($_POST){
	
	if(isset($_POST['cat_id_select'])){
	$_SESSION['cat_id_select'] = $_POST['cat_id_select'];	
	$_POST['cat_id_select'] = null;	
	header('Location: showAll_category.php');

	}
	
	if(isset($_POST['subcat_id_select'])){
	$_SESSION['subcat_id_select'] = $_POST['subcat_id_select'];	
	$_POST['subcat_id_select'] = null;	
	header('Location: showAll_subcategory.php');
	}
}
?>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>


<?php

echo "<div class='right-button-margin'>";
    echo "<a href='../standar.php' class='btn btn-primary pull-right'>";
    echo "<span class='glyphicon glyphicon'></span> Back Menu	";
    echo "</a>";
echo "</div>";

if($total_rows>0){
	        echo "<div class='page-header'>
                <h4>Last 5 instructions</h4>
            </div>";
 echo "<div>";
    echo "<table class='table table-hover table-responsive table-bordered'>";
        echo "<tr>";
            echo "<th>Name</th>";
            echo "<th>Date</th>";
			echo "<th>Actions</th>";
        echo "</tr>";
 
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
 
            extract($row);
            echo "<tr>";
			echo "<td>{$name}</td>";
			echo "<td>{$modified}</td>";
		
                echo "<td>";
 
                    echo "<a href='read_one.php?id={$id}' class='btn btn-primary left-margin'>";
                        echo "<span class='glyphicon glyphicon-list'></span> Read";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";

			}
		echo "</table>";
	echo "</div>";	

 }
// tell the user there are no users
else{
    echo "<div class='alert alert-danger'>No instructions found.</div>";
}
?>	

<?php
	        echo "<div class='page-header'>
                <h4>Category/subcategory filter</h4>
            </div>";
?>
<div>
    <table class='table table-hover table-responsive table-bordered'>
 	<form method="post">
            <tr>
                <td>
				<select id="category-select" name="cat_id_select" class="clear-right">
					<option value="0" >Select a category</option>
					<option value="1">Programy</option>

				</select>
				</td>
            	<td> 
                <button type="submit" class="btn btn-primary">Show All Category</button>
            	</td>
            	</tr>
		</form>
		<form method="post">
		<tr>
			<td>
				<select id="subcategory-select" name="subcat_id_select" class="clear-right">
				<option value="0">Select a subcategory</option>
        		<option value="1">Profilaktyka</option>

        	</optgroup>
				</select>
			</td>
			<td>
				<button type="submit" class="btn btn-primary">Show All Subcategory</button>
			</td>
			
		</tr>
		</form>
</table>
</div>
1

A gdybyś tak... Jak pisałem wcześniej... Zamiast przesuwać plik, wyciągnął tą instrukcję i wrzucił na górę index.php?


if($_POST){

    if(isset($_POST['cat_id_select'])){
    $_SESSION['cat_id_select'] = $_POST['cat_id_select'];   
    $_POST['cat_id_select'] = null; 
    **header('Location: /wp-content/themes/instrukcje/standar_show/showAll_category.php');**DRUGI BŁĄD
    }

    if(isset($_POST['subcat_id_select'])){
    $_SESSION['subcat_id_select'] = $_POST['subcat_id_select']; 
    $_POST['subcat_id_select'] = null;  
    **header('Location: /wp-content/themes/instrukcje/standar_show/showAll_subcategory.php')**;TRZECI BŁĄD
    }
}

Co i tak nie jest w pełni poprawne bo powinieneś to zrobić w functions.php (wcześniej omyłkowo napisałem theme.php) i nie rozumiem dlaczego jako Location ustawiasz pliki źródłowe skórki? Czy aby na pewno wiesz co robisz? :D

1

Dziękuję, DZIAŁA

1 użytkowników online, w tym zalogowanych: 0, gości: 1