Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Undefined Function Three Levels Down?

    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!
    Last edited by Serialcode; 03-01-2010 at 12:55 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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
    Code:
    include($_SERVER['DOCUMENT_ROOT'].'/path-to-file/file-name.php')
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Serialcode (03-01-2010)

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    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
    Code:
    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.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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
    PHP Code:
    echo $_SERVER['DOCUMENT_ROOT']; 
    Last edited by abduraooft; 03-01-2010 at 01:27 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Serialcode (03-01-2010)

  • #5
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    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
    PHP Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •