Forum Moderators: buckworks

Message Too Old, No Replies

how to use php require() with yahoo webhosting subdomain

document root is same for subdomains and main domain

         

zollerwagner

4:42 pm on May 13, 2006 (gmt 0)

10+ Year Member



I'm not sure whether to post this in the php area or here, but I'm hoping this is the forum where there will be more Yahoo gurus. (But feel free to move it, if you think it's better elsewhere!)

I'm setting up a subdomain for testing on smallbusiness.yahoo.com (yahoo's webhosting).

Normally, I like to be able to transfer files from the subdomain for testing to the live area of the site without having to change the files.

On most Apache servers I've worked with, for normal links, I can use absolute urls, like:

/folder/file.html"

That works okay on Yahoo, too.

The problem is with php includes. On most Apache servers, I use:

<?php require($_SERVER["DOCUMENT_ROOT"] . "/anyFolder/fileName.php");?>

This works with the main (live) area of the site but not on the testing subdomain. When I use require() in a file on the subdomain, php looks for the required file in the main area, not in the subdomain.

I'm not sure what to call this, but what Yahoo calls the "real root" (the most basic location in my area of the server) is "/".

The environmental variable: $_SERVER["DOCUMENT_ROOT"] returns "/" for both the live and the testing subdomain.

In a typical Apache installation $_SERVER["DOCUMENT_ROOT"] would return different values. The document_root of the subdomain would be "/subDomain". That's what makes the require() useful: the same statement can be used no matter whether it's in the subdomain or the main area.

So here's the question. Can anyone please tell me how to use require() in Yahoo so it works with the subdomains and the main live area, too?

justgowithit

10:12 pm on May 13, 2006 (gmt 0)

10+ Year Member



Why not just set your include path in your .ini and call includes by name?

zollerwagner

2:15 am on May 14, 2006 (gmt 0)

10+ Year Member



Thanks for the reply. This sounds promising. What does the code look like? I was imagining the following:
--in ini:
$header = $_SERVER['DOCUMENT_ROOT'] . "/includes/header.inc"/;

--in page:

require($header);

Now I see that there is also a variable called the ïnclude_path, which you can set using one of these methods:

include_path = .:/usr/local/lib/php:./include
ini_set("include_path", ".:../:./include:../include");

I'll try those. Thanks.

zollerwagner

3:06 am on May 14, 2006 (gmt 0)

10+ Year Member



These lines bring up a blank page, so something about these solutions isn't allowed:
include_path = .:/includes:../includes:../../includes

ini_set("include_path", ".:./includes:../includes:../../includes");

Did I do them correctly?

zollerwagner

4:51 am on May 17, 2006 (gmt 0)

10+ Year Member



Update

Yahoo has fixed the problem. I suspect that you have to request this, but they can set the server so that subdomains act like Apache subdomains.

The trick was to send a message (well, okay, a number of messages...) to the php support folks at Yahoo webhosting.

[And, yes, I do appreciate their quick and helpful response.]

zollerwagner

4:03 pm on May 29, 2006 (gmt 0)

10+ Year Member



Well, Yahoo giveth and Yahoo taketh away.

After working perfectly for a few days, my subdomain stopped working. Yahoo claims it never worked. Yeah, right.

I've been unable to find any environmental variables that point to the root of whatever domain a file is in (the subdomain's root or the main domain's root). So I stuck a little routine at the top of every page that figures out what that root is and use that value in all my php includes.

It's less elegant, but... knock on wood... it's working again.