Include URL in php - 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();
?>

Related

Include header and put index inside header html

I have a html header included with php include function however my context inside the index "Hi, World! is showing underneath my included header and not inside a html div from the header itself where I want. My screenshots:
The problem:
What I want:
So what i would like is the that my index:
<body>
<?php include('header.php'); ?>
<div >
<h3>Hi, <span class="">World!</span>
</h3>
</div>
</body>
shows inside the following div from my header.php:
<div class="content"> </div>
The problem was fixed by removing one </div> in this way the content is still opened to html further in an other document.

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.

linking to another php page and include header and footer

I am a beginner, just trying to learn php. Below is my index.php file:
<?php
include("header.php");
require_once('connect.php');
include("home.php");
include("footer.php");
?>
I made a simple test site that has the home page included inside the index.php file. Do I have to use include(header.php); on every page if I want to include the same code?
Thanks.
You dont have include header.php on every page.
Try this:
<?php include("header.php");?>
<div class="container">
<?php include ("home.php");?>
</div>
<?php include ("footer.php");?>
Keep the header and footer, just change the contents( home.php, otherpage.php, ... ).
I recommend you to use jQuery to dynamically load the content of container

Adding php to html

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/

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

Categories