Reputation: 4007
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
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
Reputation: 12508
Dont your short hand notation of php tags <? ?>
, use <?php ?>
instead...
Upvotes: 2
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