I'm trying to include the header and footer of my site as PHP include files, but can't seem to get it to work. I've changed the index.html to index.php. Then, I removed the header and footer and replaced them with PHP include statements, like so:
<?php include 'includes/header.php';?>
In the PHP include files, the code looks like this:
<footer>
<div class="container">
<div class="row">
<div class="col-sm-3">
<a class="btn btn-default" href="#" target="_blank"><i class="fab fa-facebook-f"></i></a>
<a class="btn btn-default" href="#" target="_blank"><i class="fab fa-twitter"></i></a>
</div>
<div class="col-sm-3 offset-sm-6">
<p>© 2018 Ace in the Hole</p>
</div>
</div>
</div>
</footer>
This is just the HTML code for the footer that I'm inserting into the index.php. Is there a PHP statement that should be used here to pull this information? Like an echo statement?
Thanks for any help.
Check the path of the included file
You must run the using a server like wamp,xampp etc
sample index.php
<?php
include 'includes/header.php';
?>
sample header.php file in the "includes" folder
<footer>
<div class="container">
<div class="row">
<div class="col-sm-3">
<a class="btn btn-default" href="#" target="_blank"><i class="fab fa-facebook-f"></i></a>
<a class="btn btn-default" href="#" target="_blank"><i class="fab fa-twitter"></i></a>
</div>
<div class="col-sm-3 offset-sm-6">
<p>© 2018 Ace in the Hole</p>
</div>
</div>
</div>
</footer>
I'm not sure where there error was in my paths, but I moved the includes out of their folder and onto the same level as the index.php (not ideal, bu it will do for now). They work fine this way, called in a statement like this:
<?php include 'header.php';?>
Thanks for your suggestions.
Take in mind include references directories, not urls, for instance
If you have include_me.php in /var/www/html/includes/, to include it in a file located in /var/www/html/ you should:
include(__DIR__ . "/includes/include_me.php");
also I recommend you to check your apache log looking for messages:
centos
/var/log/httpd/error_log
ubuntu/debian
By default, /var/log/apache2/error.log.
This can be configured in /etc/php5/apache2/php.ini
Hope it helps you
Related
I'm interested in solving this problem, since I can't figure out what to do. I made a fade in/out text under menu for mobile version to show some information, but since the code has to be between two HR lines I added the code to layout.php file, and now I can't put that on 3 other languages because it's on German.
<div class="">
<div class="">
<hr class="" />
<div class="" style="">
<div class="">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<hr class="" style="" />
</div>
</div>
This is the code for that fade In/Out effect and changing from one to another, I managed to do that with nth-child selector, nothing hard...
My web site has 4 languages, but every language has 2 web sites that are different. I'm not using any framework just bare code. I've tried searching for anything that would be connected to that HR line so I could add manually on every site another line and that text between them, but there is none because it uses layout.php to show that line.
<div id="" class="">
<? if ($special_fullscreen != true): ?>
<div id='' class="">
</div>
<div class="">
<div class="">
<hr class="" style="" />
<div class="" style="">
<div class="">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<hr class="" style="" />
</div>
</div>
<div class="">
<div class="">
</div>
</div>
So, I would like to hear an idea that would resolve this issue, like making a different layout.php for every language or something like that and how would that be possible. I know that this code probably doesn't have anything to do with the problem, but I'm in a hurry and just tried to copy at least something... Thanks in advance :D
I am completely not sure if I know what you mean but it may be helpful info.
If you want to include different files on the same page depended on language - you can set cookie with info about chosen language and then, based on that, load proper layout.php file for it.
You can also make all language versions in one layout.php file, include it in proper place and make if statement checking which content should get displayed (inside that layout.php file) - also based on value of COOKIE.
Instead of cookie, you can also use $_SESSION but that may not work on the way you really want (according to my understanding of your problem).
I have a HTML5 file respectively a simple webpage.
and I have a php file.
this file includes a function getKursname(string)
The function is working properly when called in the php file.
This all happens on XAMPP.
I now want to update some values and strings in my html page.
this should happen only on load.
this ist a code the code in the html:
<div class="w3-bar" id="myNavbar">
<a class="w3-bar-item w3-button w3-hover-black w3-hide-medium w3-hide-large w3-right" href="javascript:void(0);" onclick="toggleFunction()" title="Toggle Navigation Menu">
<i class="fa fa-bars"></i>
</a>
<i class="myfont icon-heart"></i> HOME
<i class="myfont icon-users"></i> ÜBER UNS
<i class="myfont icon-th"></i> KURSE
<i class="myfont icon-mail-alt"></i> KONTAKT
</a>
</div>
I want to have the innerhtml (e.g. KONTAKT)
to be read from the database.
the php function returns a string.
I can call the funcion with getKursname(string) within php.
my idea was:
<i class="myfont icon-mail-alt"></i>getKursname("kurs1")
but this is not working... :-(
thanks in advance
Dirk
Assuming you have a directory structure similar to this:
www/
index.html
functions.php
and you want to inject the content before the index.html is sent to the browser.
In which case, the solution would be, to rename index.html to index.php and at the point where you want the output of the function, you write
<?php include_once 'functions.php'; echo getKursname("kurs1"); ?>
(or require_once instead of include_once, and you have to include it only once before it is used, to load the function definition)
however, standard is to put includes in the header:
index.php
<?php
require_once 'functions.php';
?><html>
<head><!-- ... --></head>
<body><!-- ... other stuff -->
<?=getKursname("kurs1");?>
<!-- rest of page -->
</body></html>
to clarify: <?=[something] ?> is short for <?php echo [something] ?> and everything between <?php and the next ?> is evaluated by php, everything else (like the html code) is just printed as is.
I am using twitter bootstrap template in My laravel app.
I need add image which include in my imgs folder in public folder home.jpg. how can I add this image to following bootstrap scripts.
<div class="item active">
<img class="first-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="First slide">
<div class="container">
<div class="carousel-caption">
<h1>Example headline.</h1>
<p>Note: If you're viewing this page via a <code>file://</code> URL, the "next" and "previous" Glyphicon buttons on the left and right might not load/display properly due to web browser security rules.</p>
<p><a class="btn btn-lg btn-primary" href="#" role="button">Sign up today</a></p>
</div>
</div>
</div>
Laravel By default takes public folder path public/
Let's say your home.jpg file is in public/image/home.jpg
so in your html it will be <img src="http://localhost:8000/image/home.jpg">
Laravel also has specific methode {{ HTML::image('image/home.jpg') }} for this.
For mere refer http://laravel-recipes.com/recipes/185/generating-an-html-image-element
OK finally I got solutions this is working
<img class="first-slide" src="{{asset('/imgs/1.gif')}} " alt="First slide">
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
CLARIFICATION: Being that I've never used PHP, it was unclear how to format the PHP file, so that when you include it in the index, then header(nav bar) would show up. No posts explained why I had to change my index.html to index.php to make it work. And again, being that I haven't used PHP, I was under the impression that changing the extension meant that I would have to convert my HTML code to PHP commands. I was trying to avoid having to change my whole code around. That's where the confusion was.
I was going to delete the question once I got it figured out. Then again, I'm sure I'm not the only person that may run into this while making their first website.
SOLUTION. Save only the nav code in html language with a PHP extension (header.php). Change index/home file from .html to a .php extension (don't have to modify any code. but accepts the include prompt). Then, include the header.php in your index.php. Same goes for your footer. Thanks for the help everyone.
*ORIGINAL POST: Through another post, I was told it would be easier to use a nav/footer on multiple pages by using PHP.
I created a file and tried including it and it is not displaying. I'm not sure what I am doing wrong.
There is some CSS in my nav bar as well, do I need to import the css file in the PHP file? or does the index.html file automatically attach to the included (php) file.
PHP Code:
<?php
echo '<nav>
<div>
<a href="/">
<div id="logo"><img src="/Images/7serviceLOGOblue2.png" alt="Home"/></div>
<div id="headtag"><img src="/Images/title.png" alt="Home"/></div>
<div id="tagline"><img src="/Images/tag_line.png" alt="Home"/></div>
</a>
</div>
<div>
Home
<a href="/about.html" >About</a>
<a href="/services.html" >Services</a>
<a href="/pricing.html" >Pricing</a>
<a href="/contact.html" >Contact Us</a>
<input id="srchbar" type="search" placeholder="Search">
</div>
</nav>';
?>
HTML Code (include):
<body>
<?php include '/header.php';?>
....other code....
</body>
If there's a problem with the PHP file, if I'm missing something, can someone show an explain please?
no need to add <?php ?> code in the header file just keep it as it is :
Create a new file named header.php and add this code to it
<nav>
<div>
<a href="/">
<div id="logo"><img src="/Images/7serviceLOGOblue2.png" alt="Home"/></div>
<div id="headtag"><img src="/Images/title.png" alt="Home"/></div>
<div id="tagline"><img src="/Images/tag_line.png" alt="Home"/></div>
</a>
</div>
<div>
Home
<a href="/about.html" >About</a>
<a href="/services.html" >Services</a>
<a href="/pricing.html" >Pricing</a>
<a href="/contact.html" >Contact Us</a>
<input id="srchbar" type="search" placeholder="Search">
</div>
Include header.php anywhere you want
Remove the <?php tag from your code. As you generated html output. <?php tags are used to generate output by php.
<nav>
<div>
<a href="/">
<div id="logo"><img src="/Images/7serviceLOGOblue2.png" alt="Home"/></div>
<div id="headtag"><img src="/Images/title.png" alt="Home"/></div>
<div id="tagline"><img src="/Images/tag_line.png" alt="Home"/></div>
</a>
</div>
<div>
Home
<a href="/about.html" >About</a>
<a href="/services.html" >Services</a>
<a href="/pricing.html" >Pricing</a>
<a href="/contact.html" >Contact Us</a>
<input id="srchbar" type="search" placeholder="Search">
</div>
</nav>
If you want to use php tags, than you have to write the code in this way:
<?php
echo '
<nav>
<div>
<a href="/">
<div id="logo"><img src="/Images/7serviceLOGOblue2.png" alt="Home"/></div>
<div id="headtag"><img src="/Images/title.png" alt="Home"/></div>
<div id="tagline"><img src="/Images/tag_line.png" alt="Home"/></div>
</a>
</div>
<div>
Home
<a href="/about.html" >About</a>
<a href="/services.html" >Services</a>
<a href="/pricing.html" >Pricing</a>
<a href="/contact.html" >Contact Us</a>
<input id="srchbar" type="search" placeholder="Search">
</div>
</nav>
';
?>
Your problem is most likely the pathing of you include. Often you'd need to specify from the server root, and not just /header.php.
To specify your including-path, you could specify the root like this
include $_SERVER['DOCUMENT_ROOT']."/header.php";
You can also set the default include path in your php.ini file, thus making the $_SERVER['DOCUMENT_ROOT'] an automatic process, that can be done with running this code, that will alter your php.ini file.
ini_set('include_path', '/usr/lib/pear');
As others have pointed out, you don't need the contents of your /header.php to be echoed out as it's pure HTML. Anything that's included will be included the way it is, so having the contents of /header.php as pure HTML just makes for better practice, as it's easier to read.
I building my 1st responsive & dynamic website. I tested it locally on WAMP and all my sections show up but when I moved it to my 1and1.com production server my php includes didn't work. I checked the PHP versions and WAMP and 1and1 are using PHP 5.4.
Can you tell me what I overlooked or did wrong?
The PHP code is:
<?php include_once('/includes/Footer.php'); ?>
My footer looks like this:
<div id="footer">
<footer class="row">
<div class="large-12 columns">
<hr>
<div class="row">
<div class="large-8 columns">
<p>Jersey City Dance Academy 107 Westside ave. Jersey City, NJ 07305</p>
</div>
<div class="large-4 columns">
<ul class="inline-list right">
<li>Terms of use</li>
<li>Privacy Policy</li>
<li>Site Map</li>
</ul>
</div>
</div>
</div>
<div class="large-12 columns">
<div class="row">
<div class="large-8 columns">
<p>(201) 435-8943 <a mailto="Info#JerseyCityDanceAcademy.com">Info#JerseyCityDanceAcademy.com</a></p>
</div>
</div>
</div>
</footer>
</div> <!-- end #footer -->
*******UPDATE Jan 25th, 2014*****************
I moved all CSS, JS & includes files so the webpage could find them in the relative path but my includes are still not showing up. Picture showing file locations in FTP program.
http://i.stack.imgur.com/R5H94.jpg
additional 1and1 may be Case sensitive while your WAMP isn't. Check case of your filenames, Footer.php is not footer.php
You are using absolute directories for the include command.
<?php include_once('/includes/Footer.php'); ?>
Absolute directory may be different in your new hosting. You should either check the directory in which the Footer is contained or use relative directories.
<?php include_once('includes/Footer.php'); ?>
This will give you a relative path, which your local and live server may read differently.
This assumes that the 'includes' folder is in the same place as index.php
Alternatively (and the recommended method) is to have a path to the root via a variable in front of your includes, like:
<?php include_once($site_root.'includes/Footer.php'); ?>
You could even define that as a constant or put all your important data (like root paths) in an array.