Jump to content

include files


adam291086

Recommended Posts

OK here is my problem.

 

I have a domain that points to a specific folder on my host. How do i include php file that are outside that folder. If i use ../foldername it goes to the route of that folder it points to, instead of the route of the server.

 

I hope this makes sense.

 

Adam

 

 

Link to comment
https://forums.phpfreaks.com/topic/81527-include-files/
Share on other sites

The best way to handle your include folders is a file of constants in your root folder

<?php
//All constants used on the site
define("ROOT",$_SERVER['DOCUMENT_ROOT']."/ROOT/");
define("BASE", "http://mysite.com/FOLDERROOT/");
define("SCRIPTS", ROOT."scripts/");
define("SUB_FOLDER", BASE."source/");
define("GRAPHICS", BASE."graphics/");
define("SOURCES", BASE."sources/");
define("IMAGES", BASE."images/");
define("CSS", BASE."css/");
define("EXT", ".php");
?>

So when you go to include stuff on your server first track down this file (only context you will need a path for)

<?php
require_once("../constants.php");
require_once(SCRIPTS."/functions.php");
require_once(SCRIPTS."/sql_functions.php");
?>

That way if you move stuff everything updates.

 

The ROOT is for internal pointers the BASE is for urls and images for html linking

Link to comment
https://forums.phpfreaks.com/topic/81527-include-files/#findComment-413945
Share on other sites

so you are trying to link to data outside your domain?

are you trying to do something like:

root:

Domain 1:

index file for domain 1

Want index to include the include in domain 3

Domain 2:

index file for domain 2

Domain 3:

index file for domain3

include File for domain 1

Domain 4:

index file for domain 4

 

If so you will probably need to go remote and use file_get_contents of the included file

Link to comment
https://forums.phpfreaks.com/topic/81527-include-files/#findComment-413958
Share on other sites

Well i have all my php in one file. For example my database config.php. I want to be able to store this file once. At the moment i am include '../database/config.php'. This works fine else where. But in the folder where the server points to it cant find the file.

 

How would i use file_get_contents?

Link to comment
https://forums.phpfreaks.com/topic/81527-include-files/#findComment-413966
Share on other sites

i am not linking to a file in it own folder. I am linking outside a folder. Which is done correctly. But the domain that point to a specific folder on my host treats this folder as document root. Therefore ../ doesn't mean host root anymore it means root of the folder.

 

 

Link to comment
https://forums.phpfreaks.com/topic/81527-include-files/#findComment-413999
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.