TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Safe way to read file from subdomain <-> maindomain? (http://www.talkphp.com/general/2418-safe-way-read-file-subdomain-maindomain.html)

marxx 03-04-2008 06:04 PM

Safe way to read file from subdomain <-> maindomain?
 
Is there way (safe way) to read file from subdomain <-> maindomain?

Real-life scenario ;): I have subdomain (orders.mydomainx.com) and I need to read main function file from maindomain's (mydomainx.com) include folder. Possible? Hope so..

Thanks for all help!

wGEric 03-04-2008 07:17 PM

I'm guess the files are on the same machine so all you would need to know is the path on how to get from the subdomain files to the main domain files. Or the absolute path.

Gareth 03-04-2008 07:42 PM

Say you have the following file / folder structure:

[Main Folder]
+ index.html
+ include.html
+ image.gif

[Sub Folder]
+ sub.html

[Includes Folder]
+ another.html



In sub.html

To access include.html you would do the following:

PHP Code:

require_once("../include.html"); 

As you would in html

Code:

<img src="../image.gif" alt="bla" />
The two periods (.) mean that you are going a directory back (ie one . would mean you are in the same directory, two . would mean you go back one, three . would be going back two directories).

To access another.html in sub.html

You would have to go back a directory, then forward another one. Ie:

PHP Code:

require_once("../includes/another.html"); 

Alternatively you could use require(), include() and include_once().

Hope this helps

Gareth

marxx 03-05-2008 10:44 AM

Yes if folder structure looks like you show this would be easy but it isn't.. ;)

In this case folder structure looks like following:
In my main domain root folder has

Code:

httpdocs <- where is main domain files
subdomains <- where is all subdomain folders

folder view is for my main domain:
Code:

/var/www/vhosts/mydomain/httpdocs/
and subdomain:
Code:

/var/www/vhosts/mydomainname/subdomains/mysubdomainname/httpdocs/
in main subdomain folder, in each own subdomain folder has same folder hierarcy as main domain folders.
And if I try to include from my main domain files

Code:

/var/www/vhosts/mydomain.com/httpdocs/inc/function_file.php
I got this in error_log:
Code:

PHP Warning: include() [<a href='function.include'>function.include</a>]: open_basedir restriction in effect. File(/var/www/vhosts/mydomainname/httpdocs/include/include_file.php) is not within the allowed path(s): (/var/www/vhosts/mydomainname/subdomains/mysubdomainname/httpdocs:/tmp) in /var/www/vhosts/mydomainname/subdomains/mysubdomainname/httpdocs/orders.php on line 1
something about open_basedir?

Sorry about my first post, I haven't describe my problem good enough..
I have dedicated server, CentOS5 and Plesk 8.3 installed.
Thanks for all help!

wGEric 03-05-2008 09:24 PM

You can try turning off open_basedir in your php.ini file (just comment it out). Before doing that you may want to try chdir right before you include the file and then change the directory back after you've included the file. It may be easier just to turn off open_basedir though.


All times are GMT. The time now is 05:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0