I have a php page(index.php) that includes another html file(footer.html). Am using dreamweaver, and my problem is: The included file(footer.html) shows in the main file (index.php) in dreamweaver design view, but does not show in the browser preview. I have both the php files in the root directory, so they're at the same level. I have tried using require rather than include with the same result. My include code is:
<?php include("footer.html");?>
does anyone see something wrong off the bat?
Do realy exist file "footer.html"?
If no create them.
Is file "footer.html" in the same directory as "index.php"?
If no add it to the same directory.
Do you have any content in your "footer.html" file?
If no add any and check if it appears on page.
Related
Before you mark this as a duplicate from this thread, I can't get it to work. This is my situation:
Directory
parent-folder/sibling1/main.php
parent-folder/sibling2/wanted.php
So in my main.php file I want to include the wanted.php. Because of plugin functionality I cannot move the file to the same folder, I have tried this, but then the php file is not working any more.
*My attempt
<div class="parent">
<?php include('../sibling2/wanted.php'); ?>
</div>
I have tried many suggestions from other threads, but above is not working, how do I get this right?
It all depends on how the directory structure in place and therefore, what the working directory of the PHP running when "main.php" is executed. Best way to find that out would be to call the function getcwd() and to output on the page, its output.
<h1>Current directory : <?=getcwd();?></h1>
Then knowing what this directory value is, you should be able to then get the correct path to use as an include for your "wanted.php" file.
I'm trying to include other page from other folder. and i tried this and it won't show the "side.php"
<?php
include 'side.php';
?>
And the "side.php" has:
home
Well you have the answer to your question inside your question.
" Im trying to include other page from other folder"
It means that you have to go inside that folder in order to access the file
<?php
include 'folder_name/side.php'
?>
or just copy the side.php file where your working file is so that all files are in one place
Maybe I'm wrong because I don't know php so it might not work but you could check this out
Include PHP file into HTML file
I am trying to add an include of "header.php" to my inside pages BUT my PHP syntax is showing up as a comment in chrome's editor. The SAME "header.php" works fine on my home/ "index.html" page but will not on any other. Some points to note:
The route of "index.html" and "inside-page-example.html" are the same, so it's not a route problem.
The code is not written as a comment in the file. It reads:
<?php include ('inc/header.php'); ?>
So frustrating! :(
instead of
<!--?php ... ?-->
Try:
<?php ... ?>
and also change your file extension to .php (everywhere you are using php)
You do need to take out the comments, so that it's just <?php and ?>. The green text in Chrome indicates that it is being read as a comment.
You'll also need to save the file as .html with filetype as "Hypertext Markup Language" not just .txt, but I have a feeling you have that covered.
Also, you'll need to make sure that every file is in the same folder. If "inside-page-example.php" is inside a different folder, then you will need to add a forward slash or /../ for every folder you want to go up. So if you have header.php and index.php and a folder called Resume all inside "Home" folder, then when you are on Resume/index.php, you'll need to say include_once("/header.php");. A really great tool that I use when using includes is to replace the slashes with $_SERVER[DOCUMENT_ROOT]. So the include would read like this: include_once("$_SERVER[DOCUMENT_ROOT]/header.php");. This will grab header.php from the folder at the root of the server. Does that make more sense?
I'm learning php, been trying to make a cms, but when I use an include for the header this results in the page appearing as if it were written in pre tags. There's no errors when I debug or anything. And I'm completely stumped. When I put the header back in without the include it renders just fine.
<?php include("..\includes\layouts\header.php"); ?>
That's the include I'm using.
I've tried using the full path name, tried it in different browsers and using :
include($_SERVER["DOCUMENT_ROOT"]
Check that you are closing your php tags, ending your strings with semi colons etc.. My guess is that your html is being sucked into the php code which freaks out and just dumps it.
Maybe try one of the validators such as http://phpcodechecker.com (I have not used this one so I cannot comment on it's effectiveness)
Edit: I am rereading your post and I think I understand what you are trying to say - your header contains the path to your css and when you put it in a separate php file the css doesn't work? So the first thing to do is determine if the issue with the php path or the css path inside the header.php file. Look at your source code to see if the header code is being included - if it is then play around with the css path - though including the header in a php file will not cause that css path to change.
I am guessing that your header is not included at all from your mention of paths. include() works from the loading file's location. The path it wants is a server path and not a url. The one that you have above: ../includes... means that you have an include folder at the same level as the loading file such as (assume index.php is the main file):
/includes/layouts/header.php
/somedirectory/index.php
The ../ means - drop down one directory then go up from there.
If your path is more like:
/includes/layouts/header.php
/index.php
Then the include would be:
include('./includes/layouts/header.php');
Let me know if that works - if it doesn't try to explain your directory structure.
So I'm trying to make a theme from my Html file. And using require('file.php') where file.php is a series of different components of my theme. Now when I access the file directly, I still see the html. How do I make it display a blank page when user accesses the file.php directly?
Explanation
So let's say I make index.php and I want to include the header file(header.php)
When I require('header.php'), everything works perfect. Now when I try to access the header.php, I can see the html content of it. How to I make this appear blank instead of seeing the header.php piece?
Thanks
In that case, If you want to execute header.php inside the index.php or etc. You need to add or define a flag in parent files (wherever you want header.php to be executed or simply adding in to the common file which is called in all parent files), In header.php file you need check the defined flag is set or has some value. If it is not set, then stop execution by using die(); function.
In index.php,
<?php $HeaderAllow ='1'; ?>
In header file,
<?php
if($HeaderAllow=='' or !isset($HeaderAllow)){
die();
}
?>
you can use $_SERVER['SCRIPT_FILENAME'] here to check and then make page blank in header.php.
<?php
if($_SERVER['SCRIPT_FILENAME'] == 'header.php') {
exit();
}
Putting the include files in a seperate folder and protectinng with .htaccess is good idea.
Same issue here.
deny direct access to a folder and file by htaccess
The easiest way is to put your includes in a directory and deny access to that directory in your .htaccess file