Creating a footer file using php [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
I'm trying to create a php file with my footer details. I want to include this into the necessary pages. The following is my footer.php
footer.php
<?php
echo "<footer class="footer">
<div class="container">
<p class="text-muted">Contact Us</p>
<p class="text-muted"> Copyright © <span id="yearfooter"> </span>. All rights reserved.</p>
</div>
</footer>";
?>
This is the line I include into my html file to include this footer.php
<?php include 'footer.php'; ?>
But when uploaded to my website, it is not showing the footer file. This is the very first time I'm trying out PHP. I'm not sure if there is something else I'm supposed to do or where I'm going wrong. Any help is much appreciated!
UPDATE
I still cant get this to work. I've also added a .htaccess file and it still doesnt help.
.htaccess
AddType application/x-httpd-php .html
Update
I've managed to get this working. There was some config issues in the server side. Thanks!

Try wrapping your echo in single quotes:
<?php
echo '<footer class="footer">
<div class="container">
<p class="text-muted">Contact Us</p>
<p class="text-muted"> Copyright © <span id="yearfooter"> </span>. All rights reserved. </p>
</div>
</footer>';
?>
And no space between ? and php
<?php include 'footer.php'; ?>

Related

Why is my <footer></footer> not appearing in PHP using include function? [duplicate]

This question already has answers here:
how to embed html files in php code?
(4 answers)
Reference - What does this error mean in PHP?
(38 answers)
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 3 years ago.
I have been using this index.php format:
<?php
//this is to include the header
require 'includes/header.php';
//this is to include the content menu
include 'includes/content.php';
?>
<?php
//this is to include the footer
include 'includes/footer.php';
?>
And the server does not seem to catch the includes/footer.php file as when I go to developer tools it shows the following without the footer tag:
And this is my footer.php file:
<footer class="website-footer fixed-bottom">
<div class="container">
<div class="row">
<div id="logo">Whit<span>BLOG</span></div>
</div>
<div class="row">
<div class="col-sm">Copyright © Made with love by Jason ♥ </div>
<div class="col-sm">
<ul class="footer-nav">
<div class="footer-content">
<li>Home</li>
<li>Gallery</li>
<li>About Us</li>
<li>Contact Us</li>
</div>
</ul>
</div>
</div>
</div>
</footer>
</body>
Anyone may have an idea of what is the issue?

Read php file if I am in a folder

I created a footer.php file:
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col col-md-5">
<p>Copyright © 2018 Nens Events.</p>
</div>
</div>
</div>`
and it is located on a folder like this one:
/php/footer.php
All I want is to read it on a subfolder like this one: /events/na/1.php
but when I use this code, it doesn't read the footer.php file, does someone know what I am doing wrong?
<?php
echo file_get_contents("/php/footer.php");
?>
Use include() or require() function to join your codes into your script.
So the code for reading(in your terms) will be like this
<?php include 'php/footer.php'; ?>
If the site is on root page, use absolute path like this.
<?php include '/php/footer.php'; ?>
It should work! Give a try.
Use require('php/footer.php') for better coding.

included php "template" moved downwards [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Edit: Fixed, moved <?php include(haeder.php); ?> to the top and replaced the outsourced part with <?php showheader(); ?>.
I've been creating a little website, and as its menubar started to get full I wanted to "outsource" it to a separate file.
<body>
<div style="width:800px;margin:0px auto">
<!-- outsourced part -->
<div style="height:50px;background-color:#ff0000">
Header
</div>
<!-- end of outsourced part -->
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
So I copied the outsourced part and pasted it into a new file called header.php and replaced it with
<?php include("header.php") ?>
so now the code is
<body>
<div style="width:800px;margin:0px auto">
<?php include('header.php') ?>
<div style="margin-top:10px;background-color:#00ff00">
hello world
</div>
</div>
</body>
Now when I open the website again the header and everything after it has moved downwards. How can I prevent this from happening? I have PHP 5.6.14 installed on XAMPP and PHP 5.3.3 on a Linux server.
Uploaded the 2 files here
I tested your file and I could see the issue. Usually this is because you got an invisible character in the page. So go into the Chrome debugger, Elements view, and expand the code. You'll find the following before your header <div> tag.
"
"
from the debugger, you can delete it, and you'll see your page displays fine again. So cleanup your 2 php file. One is having an invisible character.
I believe the reason is that your index.php file in UTF8-BOM encoded while the header.php is just UTF8 - make sure to use the same encoding to avoid these issues.

I Can't Get The Virtual Include To Work, Do I need an extension?

so I have the include saved in a folder called "include" and the file name is menu. When I upload the site, it doesn't show. Do I need an extension? Do I have to do it with php? Help me please. Here's my code. the website is www.martinshaba.zzl.org
</head>
<body>
<div id="container">
<div id="header_line">
<div class="header">
<!--#include virtual="/inlcude/menu.html" -->
<p>MARTIN SHABA</p>
</div>
</div>
The #include tag is nothing to do with PHP, but is an Apache module. That module itself is, however, rarely used these days, and so you may do better to indeed use PHP, though you will have to name the file with a .php extension for that to be parsed.
<div class="header">
<?php
include "/include/menu.html";
?>
<p>MARTIN SHABA</p> <!-- etc.... -->

Run PHP into *.html extension (mime type) [duplicate]

This question already has answers here:
How do I add PHP code/file to HTML(.html) files?
(12 answers)
Closed 8 years ago.
I have xampp and I have a project that extensions are
*. html and php code have my localhost php does not interpret the code and displays it as php, but I want to run as php code ex:
index.html
<?php
$seccion='inicio';
require_once("idiomas.html");
require_once("configurador.html");
require_once("header_scripts_css.html");
?>
<body class="clearfix">
<header id="header">
<?php require_once("header.html"); ?>
</header>
<?php require_once("slider.html"); ?>
<div id="centro">
<?php require_once("central.html");?>
</div>
<?php require_once("footer.html"); ?>
you can add
AddType application/x-httpd-php .html
into your .htaccess file or you can modify apache mod-php5 setting

Categories