Forum Moderators: coopster

Message Too Old, No Replies

Subdomains and Server Includes

         

lanesharon

4:20 am on Dec 15, 2005 (gmt 0)

10+ Year Member



I am having the same problem I have had in the past. I have a snippet of code that I placed in a #*$!.php file in my domain root directory. I want to access it from several of my subdomains, in html code. I have tried a number of SSI and php code lines and I still get nothing. I have tried absolute path:
<? include("home/me/public_html/snippet.php")?>

I have tried:
<!--#include virtual="../snippet.php" --> thinking that my hosting company uses subdomains as if they were subdirectories.

And lastly, I tried a direct URL call:
<? include("http://www.mydomain.com/snippet.php")?>

I can't seem to get it to work. Can anyone give me suggestions?

jatar_k

3:49 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if this is the absolute path from the server root

<? include("home/me/public_html/snippet.php")?>

then you need to add a leading slash

<? include("/home/me/public_html/snippet.php")?>

try that

Anyango

4:53 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i totally agree with Jatar_k

you need to add a leading slash, because on linux servers root comes after /.

i would just like to add that


<? include("http://www.mydomain.com/snippet.php")?>

this can never work the way you want it, this include will be a compiled output html include of snippet.php, it in no way can be a source code include. you cannot include source code of any file by sending http request.

coopster

1:40 pm on Dec 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another good practice here is to use the DOCUMENT_ROOT $_SERVER variable. Your code will then port to other servers and even other platforms without changes.