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
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 want to use this database config file which located in-> "/main/config.php" directory. Now please tell me how can i include that config.php from-> "/main/admin/login.php" file.
i have simply tried following but not worked-
<?php
include "/main/config.php";
?>
thanks in advance
If you are trying to go back to the file directory then this will include the file. However you have missed the brackets.
<?php include("../main/config.php"); ?>
I have a file here: public_html/wiki/index.php
Im calling these files:
<?php
include "../auth.php";
include "../header.php";
?>
However, my page looks like this:
If I paste the same file in public_html/index.php then it will look like this:
I think I've narrowed it down to my header.php file which is being called from /wiki/ but header calls files from ../css.. and ../js and so on.
How can this be adressed? I've looked at many posts already which tells me to define a global variable but it doesn't help me. Like so:
<?php //config file in root folder
define("ROOT", __DIR__ ."/");
?>
and then calling them with this:
<?php
include_once("../config.php");
include (ROOT ."auth.php");
include (ROOT ."header.php");
?>
How should I do this so I can get all my javascripts and the actual site with me in another folder?
NOTE: I WANTED THIS AS A COMMENT BUT DO NOT HAVE THE REP
We have a different folder structure, but it is good practice to put your includes in one folder and from there link all the JS files (best practice is, place them in a pre-footer for speed) and then do
<?php include $_SERVER['DOCUMENT_ROOT'].'/includes/page-footer.php'; ?>
Just change the file name to suit you :) hope this helps
the problem was my include file didnt specify links as /js/file.js
i had them as js/file.js.
thanks #cd001
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.
I've been using the php include function for my navbar for my website. It works well but....
My HTML says
<?php include 'include/navbar.html'; ?>
Now if I have a HTML page in /techpages/toptech.html so I would like to change my php include to <?php include 'http://example.com/include/navbar.html'; ?>. The problem is I get heaps of errors then.
Can someone help me?
Can someone answer one of these questions?
How can I make the PHP include function work with a full URL?
HTML has ../ to go into the parent folder. Is there a CSS equivilant?
Any help would be much appreciated.
Here are two approaches which I think will work for what I imagine you are trying to achieve:
You could include via include $_SERVER['DOCUMENT_ROOT'].'/include/navbar.html'; - this will always include the same file regardless of in what file in what directory you put the include
PHP has an include_path which specifies where to look for file-includes, you can add the /include directory in this include_path and from there on always include via include 'navbar.html'. But to be able to do this you have to have permission to access/modi the php.ini...
One of the options of doing that is:
include($_SERVER['DOCUMENT_ROOT']."/include/navbar.php");