Forum Moderators: coopster
I've managed to find PHP equivalents for most of my current includes, but I am struggling with the script (RatLog) that I use for counting creating my referral logs.
php include() doesn't seem to work on CGI, so I am having to use php virtual(). However, I can only get virtual() working with a path relative to root, not with the full path. But since I also plan to turn some sections into subdomains, my understanding is that relative to root will only work for the main domain, not the subdomains.
Can CGI be included using PHP in any other fashion? Is it perhaps a configuration issue with my host that is causing this problem? When I use php include() for regular files, they only work with full server path, not with a relative-to-root path. The version of PHP on the server is 4.3.7.
print join(file("filename"),''); eg print join(file($_SERVER['DOCUMENT_ROOT']."/footer.txt"),'');
and
print join(file("url"),''); eg print join(file("http://www.example.com/footer.html"),'');
Note that $_SERVER['DOCUMENT_ROOT'] can be used also with include and virtual - to ensure that the current path does not affect which file is used.
HTH and welcome to WebmasterWorld.
I am pretty new to PHP, so I might be misunderstanding, but wouldn't $_SERVER['DOCUMENT_ROOT']."/footer.txt" be the same as specifying /footer.txt? That is, wouldn't it count only from the root html directory, rather than from the user root?
I can get <?php virtual("/Scripts/RatLog/ratlog.cgi");?> to work, but not <?php virtual("/home/sites/westeros.org/www/html/Scripts/RatLog/ratlog.cgi");?>. However, if I understand things correctly, using just the path from root (as in the first example) won't work if I try to use the script across subdomains since each of these will have their own document root.
I am pretty new to PHP, so I might be misunderstanding, but wouldn't $_SERVER['DOCUMENT_ROOT']."/footer.txt" be the same as specifying /footer.txt? That is, wouldn't it count only from the root html directory, rather than from the user root?
Nope -
$_SERVER['DOCUMENT_ROOT']."/footer.txt" == /home/sites/example.com/footer.txt
/footer.txt == /footer.txt -- the root of the file system - so will fail.
or relative paths eg.
footer.txt == "current working directory/" footer.txt - so won't work if you use subdirectories [example.com...] - would fail unless you also have footer.txt in the Stuff directory.
I can get <?php virtual("/Scripts/RatLog/ratlog.cgi");?> to work, but not <?php virtual("/home/sites/example.com/www/html/Scripts/RatLog/ratlog.cgi");?>.
Your first example shouldn't work, is it not <?php virtual("Scripts/RatLog/ratlog.cgi");?> that is working? a relative path.
However, if I understand things correctly, using just the path from root (as in the first example) won't work if I try to use the script across subdomains since each of these will have their own document root.
Yep that's right. So either have copies of them in each sub domains root. Or lookup:
symlinks
include_paths
You have lots of options :)
[php.net...] -- quite a few user contributed notes there as well.
I also tried the two methods you suggested, with $_SERVER['DOCUMENT_ROOT'] and URL. The first results in the content of the script ending up on the page, whereas the second gives no error messages, no script content on the page, but also no log entry for the page, just one for the .cgi file itself.
Note that for a CGI script, the script must generate valid CGI headers. At the minimum that means it must generate a Content-type header.- PHP manual.
So - your current cgi produces good headers? And it all works on your main script? And the subdomains are the only problem?
To be honest the other methods I suggested won't pass on the full variables (such as referer) so wouldn't be much use.
To answer the subdomains request - you'll have to ensure that each subdomain will answer the request for Scripts/Ratlog.cgi. You can do this by setting up .htaccess to rewrite the query, see: [httpd.apache.org...] in Passthrough mode.
or
Setting an alias in the .htaccess/httpd.conf file. [httpd.apache.org...]
It depends on how your server is setup. Hopefully someone else will pick up on this thread whose done this and give you the exact config.
All I can really say about the CGI is that it works when I use my current SSI method to include it (using <!--#exec cmd="/home/sites/westeros.org/www/html/Scripts/RatLog/ratlog.cgi"-->) and it works when I use <?php virtual("/Scripts/RatLog/ratlog.cgi");?>.
I don't suppose there's a PHP command that corresponds to exec cmd? I know that I wasn't able to get it working under SSI either with regular includes.
I'll see if I can figure out how to get it to work with subdomains from the information you provided. Thanks a lot for trying to sort it out. :)