...

View Full Version : Undefined Function Three Levels Down?



Serialcode
03-01-2010, 01:53 PM
Hello,

I'm having a problem with a PHP script that seems very odd to me. I am linking and including directly to files (using "http://" and not just "../") I use for a rating system.

When making a php call in pages that are three levels away from where the base PHP, CSS, and JS files for this rating system are, I get an error.

I have this rating system implemented on over 25 pages and I have tried moving the specific pages I'm working with up one level to find that I no longer get the error.


Here's an example of my site structure:


root/rating - home of the base files

root/alpha/index.php - a page with a working script

root/alpha/beta/index.php - a page with a working script

/root/alpha/beta/gamma/index.php - a page using identical code, script gets an error



Does anyone have any idea why this is? I'm getting there error with the php call that is actually in the body of the page, no error with the includes that are in the header.


Thanks you!

abduraooft
03-01-2010, 02:00 PM
I'm having a problem with a PHP script that seems very odd to me. I am linking and including directly to files (using "http://" and not just "../") I use for a rating system. include() or require() need the path in your system and not the http:// path. If you need to use the same path in all your include statements, you may use the absolute path like

include($_SERVER['DOCUMENT_ROOT'].'/path-to-file/file-name.php')

Serialcode
03-01-2010, 02:12 PM
include() or require() need the path in your system and not the http:// path. If you need to use the same path in all your include statements, you may use the absolute path like

include($_SERVER['DOCUMENT_ROOT'].'/path-to-file/file-name.php')

Would I put the server path (something like home/our site/public_html/rating/the php file is here) in the '/path-to-file' part?


If so, what would I input for _SERVER and ['DOCUMENT_ROOT'] parts?

I'm sure this varies, so my upfront apologies for such a probably absurdly obvious question. :D

abduraooft
03-01-2010, 02:24 PM
Nothing to with that php global variable. It'll give you the path up to your servers root directory. So, what you need is to append the right path from root to that file to be included. Check http://php.net/manual/en/reserved.variables.server.php
'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.
Check the output of
echo $_SERVER['DOCUMENT_ROOT'];

Serialcode
03-01-2010, 03:40 PM
Nothing to with that php global variable. It'll give you the path up to your servers root directory. So, what you need is to append the right path from root to that file to be included. Check http://php.net/manual/en/reserved.variables.server.php
Check the output of
echo $_SERVER['DOCUMENT_ROOT'];

It inputs the information itself. I see. So what is *not* including in the output of that echo is what goes in the path to file part.

Tried it and it is now working! I'm not sure why the developer that provided this script did not have it coded this way.

Anyway, THANK YOU! You have been very, very helpful and managed to save me from having a lot of redundant copies of this script and its associated files from being scattered around my server! :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum