TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-04-2008, 06:04 PM   #1 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default 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!
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Old 03-04-2008, 07:17 PM   #2 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

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.
__________________
Eric
wGEric is offline  
Reply With Quote
Old 03-04-2008, 07:42 PM   #3 (permalink)
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default

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
Gareth is offline  
Reply With Quote
Old 03-05-2008, 10:44 AM   #4 (permalink)
The Contributor
 
marxx's Avatar
 
Join Date: Sep 2007
Location: Finland
Posts: 45
Thanks: 3
marxx is on a distinguished road
Default

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!
Send a message via MSN to marxx
marxx is offline  
Reply With Quote
Old 03-05-2008, 09:24 PM   #5 (permalink)
The Acquainted
 
wGEric's Avatar
 
Join Date: Nov 2007
Posts: 166
Thanks: 0
wGEric is on a distinguished road
Default

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.
__________________
Eric
wGEric is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:08 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design