3

I am trying to include a php file from a parent domain in a subdomain.

In subdomain.parentdomain.com/test.php i have

include ('/var/www/vhosts/parentdomain.com/website/wp-blog-header.php');

My subdomain structure looks like

$_SERVER['DOCUMENT_ROOT'] gives /var/www/vhosts/parentdomain.com/subdomain.parentdomain.com

I have server access with plesk 11, but i don't know which php setting i have to change to enable including files from parent domain?

5
  • What's the document root of the "parent domain"?
    – MrWhite
    Nov 25, 2014 at 11:53
  • @w3d you were right about my question, it was a stupid idea! Thanks, I've deleted it. Nov 25, 2014 at 12:17
  • @w3d doc root is /var/www/vhosts/parentdomain.com/ I have a sort of working solution by ini_set("include_path", "/var/www/vhosts/parentdomain.com/httpdocs/website/"); require "wp-blog-header.php";
    – alex
    Nov 25, 2014 at 17:50
  • Changing the include_path will be the same as specifying the path in the include itself... ie. require '/var/www/vhosts/parentdomain.com/httpdocs/website/wp-blog-header.php';? Which is 2 sub directories under the primary domains document root, according to what you've reported.
    – MrWhite
    Nov 25, 2014 at 18:08
  • Why not use the explicit vs a relative path?
    – psiclone
    Sep 7, 2017 at 17:30

2 Answers 2

1

You can change PHP settings and the document root.

This should will help you to include files:

<?php

include_once $_SERVER['DOCUMENT_ROOT'] .  '/../inc/header.php';

This part is the trick: /../

1
$url = file_get_contents('http://example.com/page.html');

You can get the contents of an external domain with this method. If this is somehow slower than calling the file directly from your server directory and that's the problem please do let me know.

If the issue is that you cannot use file_get_contents or similar commands with your PHP settings, you have to log into your PHP root control panel and modify your PHP. You need to set settings such as urlopen (or commands similar to that name) to ON. I've had to modify these settings in the past with new servers that I've setup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.