Adding php to html - php

I added some php to some of my pages, but its not coming up on any of the pages.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('/Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
in the php file I had this.
<header>
<a href="#" class="menu-toggle">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
<nav class="menu-side">
<div class="listing">
<div class="box"><a class="list" href="/"><h1>Home</h1></a></div>
<div class="box"><a class="list" href="/DayZ_Home/"><h1>DayZ</h1></a></div>
<div class="box"><a class="list" href="/Photos/"><h1>Photos</h1></a></div>
<div class="box"><a class="list" href="/Store/"><h1>Store</h1></a></div>
</div>
</nav>
</header>
This is the exact same for all my pages, and nothing is coming up.
This is the error I get:
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening '/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
Any Idea what is wrong?

Simply try this first : Remove slash in front of php in the path and run again.
If that don't work continue reading.
Let me help you as much as I can.
First thing first, this
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening'/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
(just stating the obvious to me) This means,
There is a FIle called 'index.php' in public_html directory
It has a function "include()" on line 14 in its code.
The include function have a path in parenthesis following it.
There is a error in that path.
Either file "Slider.php" is not there or the script can't read it.
how do i know it for sure ?
Failed opening'/Php/Slider.php' for inclusion
Why did I tell this ?
It will help to understand errors next time.
Now let's try to solve the error, what I would do first to confirm the file permissions and every other thing is
Move the file to "public_html" folder itself.
new Path will be just Slider.php (Take note of the case).
Run your script and look for errors now.
That is the simplest way to do it.
Be very very precise in the "case" becuase I see you are not using the php conventions of naming everything.
Report back with the directory structure so we can help further.

'/Php/Slider.php' I assume you have Slider.php inside Php directory, Now the correct way to include would be:
require ('../Php/Slider.php');
Which will go back first, open the Php directory folder and look for Slider.php file.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('../Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
EDIT:
Moving forward from the comments under this answer, you stated your directory structure as:
/public_html/index.php (home page)
/public_html/Php/Slider.php
Which means the approach I stated was fine.
To go from index.php to Slider.php the way would be:
../ (Go back)
Php/ (Open the Php directory)
Slider.php (Look for Slider.php)
Hence, require ('../Php/Slider.php');

As you mentioned that you are including this file in whole project , yet you did not mention the dirctory structure . It is always better to include files with absolute path .
try as below -
<body class="menu">
<!-- Slide bar starts here -->
<?php
$file=$_SERVER['DOCUMENT_ROOT']."<--your project dir-->".'/Php/Slider.php';
require ($file);
?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>

<?php require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");?>
$_SERVER["DOCUMENT_ROOT"]. Makes your path start at /public_html/

Related

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.

How to include and link menu file into every webpage using HTML?

I have researched some answers that talk about php, javascript, iframes etc. but I have tried a couple and none of them work. I am new to HTML coding.. and coding in general!
<link rel="menu" href="menu.html"> does nothing
<!--#include virtual="/menu.html" --> does nothing (presumably because its a comment?)
<iframe src="page.html"></iframe>
or object... both place the menu in a silly little scroll box.
I want to run my menu on my page as if it were a function in C. Where I can just include it, and it be there, or just link it.
Thanks for the help!
Ryan
webpage file: biology.html
menu file: menu.html
<div class="container">
<img src="homeicon.jpg" width="50" alt="Home">
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
Telecommunications
Electronic Engineering
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
About me
Youtube
</div>
</div>
</div>
</div>
You can use php to include files on other pages. Here is some example code to get you started:
<?php
require_once('menu.php');
?>
You can put this in your HTML page appropriately, however you must make sure that php can be processed on your server and the file containing php code must end in the .php extension.
There are also other methods of including files via php, see here:
http://php.net/manual/en/function.include.php
and
http://php.net/manual/en/function.require.php
Edit - I'm not a big fan of this approach, but it will work on Github pages.
Create a file called nav.js with your menu defined as a js variable, then use javascript to insert it into an empty div created on each page. This way to update your nav you only have to ever edit nav.js Not pretty but it works
nav.js
var navigation = "<nav>";
navigation += "<ul>";
navigation += "<li>Home</li>";
navigation += "<li>About</li>";
navigation += "</ul>";
navigation += "</nav>";
document.getElementById("navigation").innerHTML = navigation;
Other pages
<div id="navigation"></div>
<!--rest of page goes here.-->
<script src="nav.js"></script>
Fiddle: https://jsfiddle.net/ze3hLxx8/1/
There are multiple ways to include a file into another depending on the backend technology you wish / want / need to use.
PHP
The most common way to do it in php is by using the include or require statement inside a php file.
In your specific case your biology.html file must be converted to a biology.php file and then you can add the relative code to include the file:
<?php include('menu.php');?>
This simple statement will add the content in your menu.php file to the current page. This will not work if php is not present on the server and obviously will not work locally without a local development environment
The differences between require and include can be found on the official documentation:
include: http://php.net/manual/en/function.include.php
require: http://php.net/manual/en/function.require.php
SSI
Another method is to use Server Side Includes. To use the SSI it must be supported and enabled on the webserver. To use SSI you need to change the extension from biology.html to biology.shtml and then add the following statement:
<!--#include file="menu.html" -->
More information on server side includes can be found on wikipedia: https://en.wikipedia.org/wiki/Server_Side_Includes

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.... -->

php include error

I am trying to include a header which i made separately into my index page. When I try to include and run it, it does not display the header that I made although the paths are all correct. please help me on this. thanks. I am a newbie in php, css and html.
Here is the link for pictures and codes: http://www.fileden.com/files/2011/7/27/3174077/My_Documents/Folder.rar
include code:
</head>
<body>
<div id="main_container">
<div>
<?php
include 'include/header2.php';
?>
</div>
<div class="main_content">
<div class="menu">
<ul>
<li><a class="current" href="../../index.php">Home</a></li>
<li>Job Orders<!--[if IE 7]><!--><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul>
so on and so forth...
I can only guess, but I think 'include/header2.php' is pointing at something other than what you intend it to. Take a look at the docs on include path. You can check your current include_path with phpinfo and work from there.
Yeah, turn on error reporting and see what php is telling you. You can also try to give an absolute path for your include, like:
include('/var/web/include/header2.php');
It's not really advisable to use absolute paths like this, but it might help you find out what exactly is going wrong.

Include URL in php

My form create by php script and between teo file:
index.php
header.php
In index.php, i try in
...
<div class="art-header-png"></div>
<div class="art-header-jpeg"></div>
<?php include("header.php"); ?>
</div>
<div class="art-nav">
<div class="l"></div>
<div class="r"></div>
and my header.php
<div class="art-logo">
<h1 id="name-text" class="art-logo-name">Your Title Goes Here</h1>
<div id="slogan-text" class="art-logo-text">Your Slogan Goes Here</div>
</div>
But it didn't show content inside header.php.
How can i make it work?
First thing, either place header.php in the same folder as index.php or specify the correct path relative to index.php when you are using include (same apply to require).
PHP Include
also check to see if your php is configured correctly as well. Save the following line of code in a php file. Run it and see if you get php window:
<?php
phpinfo();
?>

Categories