David
David

Reputation: 4007

php include breaking

I have a php page that generates all the html and echo's it. Now I want to write a php script that I can use include to handle the footer code. that way if I need to update the footer on all the pages I can just edit the code in the included page.

But when I use include("footer.php"); and the footer page contains the footer code that works if it exists on the page it breaks and prints the code. Im very confused as too why?

  if(isset($_SESSION['user_cart']) && count($_SESSION['user_cart']) > 0)

Starts writing the code on the page if I include from 0)

Please help?

EDIT: The code in the footer is wrapped in <?php ?>

Upvotes: 0

Views: 978

Answers (5)

Blazedd
Blazedd

Reputation: 20

I'm not sure if you stated your question very clearly.

If you are echoing code out it will appear as soon as you include the file. Your file should look like this:

<?php require_once 'header.php';
// content goes here
require_once 'footer.php'; ?>

Upvotes: 0

Weston
Weston

Reputation: 1857

Please make sure that your footer file has <?php in the beginning.

Upvotes: 1

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

Dont your short hand notation of php tags <? ?>, use <?php ?>instead...

Upvotes: 2

Jarosław Gomułka
Jarosław Gomułka

Reputation: 4995

It sound like you didn't start php file with

<?php

Upvotes: 1

John Smith
John Smith

Reputation: 31

You need to wrap that code in footer.php with php tags.

<?php

 if(isset($_SESSION['user_cart']) && count($_SESSION['user_cart']) > 0) ...

?>

Upvotes: 3

Related Questions