How to include
Moderator: General Moderators
How to include
Hi there,
I have a free hosting package at one free host provider. Say my url is http://stockpedia.110mb.com. So at first I had the following file structure in my vista panel:
Directory tree: root/
(folder)htdocs
(file)DO NOT UPLOAD FILES HERE
Then I purchased a domain say stockpedia.com and add-on it to the free host. So my previous file structure became this:
Directory tree: root/
(folder)htdocs
(folder)stockpedia.com
(file)DO NOT UPLOAD FILES HERE
If I click (folder)stockpedia.com then it contains the following structure:
Directory tree: root/stockpedia.com
(folder)UP..
(folder)htdocs
My question is, here this htdocs is the root directory for stockpedia.com domain or not?
If it is the root directory for stockpedia.com domain then I want to have a folder outside of the root directory and want to include files from that folder so that files remains in this folder cannot be directly accessible. Say I made a folder "includes" outside of the directory htdocs. So the structure became this:
Directory tree: root/stockpedia.com
(folder)Up..
(folder)htdocs
(folder)includes
Now my index file for the stockpedia.com will be inside "htdocs" folder and suppose I have putted header.php and menu.php files inside that includes folder. Now I want to include those header.php and menu.php file in index file which is under htdocs folder. I wrote this code to include:
[file: index.php]
<?php
include("/includes/header.php");
include("/includes/menu.php");
echo "This is my index page for stockpedia.com";
?>
but the index file is unable to include those header or menu.php. My second question is what should I write to include those files in index page?
I have a free hosting package at one free host provider. Say my url is http://stockpedia.110mb.com. So at first I had the following file structure in my vista panel:
Directory tree: root/
(folder)htdocs
(file)DO NOT UPLOAD FILES HERE
Then I purchased a domain say stockpedia.com and add-on it to the free host. So my previous file structure became this:
Directory tree: root/
(folder)htdocs
(folder)stockpedia.com
(file)DO NOT UPLOAD FILES HERE
If I click (folder)stockpedia.com then it contains the following structure:
Directory tree: root/stockpedia.com
(folder)UP..
(folder)htdocs
My question is, here this htdocs is the root directory for stockpedia.com domain or not?
If it is the root directory for stockpedia.com domain then I want to have a folder outside of the root directory and want to include files from that folder so that files remains in this folder cannot be directly accessible. Say I made a folder "includes" outside of the directory htdocs. So the structure became this:
Directory tree: root/stockpedia.com
(folder)Up..
(folder)htdocs
(folder)includes
Now my index file for the stockpedia.com will be inside "htdocs" folder and suppose I have putted header.php and menu.php files inside that includes folder. Now I want to include those header.php and menu.php file in index file which is under htdocs folder. I wrote this code to include:
[file: index.php]
<?php
include("/includes/header.php");
include("/includes/menu.php");
echo "This is my index page for stockpedia.com";
?>
but the index file is unable to include those header or menu.php. My second question is what should I write to include those files in index page?
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: How to include
Hello infomamun,
It looks like you need to add .. to each of those includes:
include("../includes/header.php");
include("../includes/menu.php");
Cheers
PS If you used the forward slash to indicate the root folder, the misunderstand you have there is the root folder is the root folder of the server, not the website. Therefore, / points to /root, and not /root/htdocs/stockpedia.com/
It looks like you need to add .. to each of those includes:
include("../includes/header.php");
include("../includes/menu.php");
Cheers
PS If you used the forward slash to indicate the root folder, the misunderstand you have there is the root folder is the root folder of the server, not the website. Therefore, / points to /root, and not /root/htdocs/stockpedia.com/
Re: How to include
Hi PHPHorizon
Thanks for your reply. Brother bt in practical, it is not working. I created a folder named "includes" outside of htdocs folder, placed a file inside includes folder and trying to include it from file inside htdocs folder using "../includes/test.php" but it is not working. I dont know why. Should i have to change folder permission? Would you please clear it a little bit more?
Thanks for your reply. Brother bt in practical, it is not working. I created a folder named "includes" outside of htdocs folder, placed a file inside includes folder and trying to include it from file inside htdocs folder using "../includes/test.php" but it is not working. I dont know why. Should i have to change folder permission? Would you please clear it a little bit more?
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: How to include
You can use the function getcwd() to determine what path your script is operating under. Echo the value returned by that function. Let's see what path you're dealing with, and then we can figure out a path to the includes.
Cheers
Cheers
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: How to include
If you are using 110mb dot com and added a domain, then you don't need to change your file structure. You need to change the dns record of stockpedia.com so that it points to your 110mb dot com IP address.
http://stockpedia.110mb.com and http://stockpedia.com will show the same content.
http://stockpedia.110mb.com and http://stockpedia.com will show the same content.
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: How to include
I'm sorry internet-solution, but I have to disagree with you a little bit here. The OP is including files through the file system, not through the internet (i.e., by using an HTTP wrapper) and therefore, any DNS settings are inconsequential to this problem.
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: How to include
PHPHorizon, you are right from the syntax point of view.
What I meant to point out that the OP's efforts might be wasted, as there is no need to change the directory structure. Pointing the new domains to the free host's IP will achieve what he wants to do.
What I meant to point out that the OP's efforts might be wasted, as there is no need to change the directory structure. Pointing the new domains to the free host's IP will achieve what he wants to do.
- PHPHorizons
- Forum Contributor
- Posts: 175
- Joined: Mon Sep 14, 2009 11:38 pm
Re: How to include
Apologies internet-solution,
I see your point and I agree with you now. Cheers
I see your point and I agree with you now. Cheers
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: How to include
Thanks to both of you for yours valuable advices. Cheers.