Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Server['document_root']

Options
  • 16-12-2006 1:49pm
    #1
    Registered Users Posts: 673 ✭✭✭


    Hi,

    Im having problems fuguring out what is going on exactly when i use SERVER in my php scripts. On my testing server i have set the document root to the root folder where my site is.

    On the homepage if i use an includes such as:

    <?php include $_SERVER.'/mysite-includes/user-login.php';?>

    this seems to work on both the live server and my apache server, but if i use this code (which lies in the included file) to locate to an image location:

    <img src="<?php include $_SERVER;?>/mysite-images/12.jpg" width="21" height="20" align="absmiddle">

    This works on the live server but not on my testing server.

    Anyone know why this is happening?

    Thanks


Comments

  • Registered Users Posts: 2,157 ✭✭✭Serbian


    You should never use $_SERVER; to reference files on your server. You are exposing the filestructure of your machine for a start and it's bad practice. All images should be referenced relevant to the site root. So, say you keep all your images in the images folder, you should link to any image as <img src="/images/image.png" alt="Image" />.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    Thanks, i was using something like ../images/12.jpg i.e. with the ../ before the file location but that was giving me problems when i was on a page in a subfolder. The images seem to be working fine now.

    I am getting a problem now when i try to include a file using /mysite-includes-files/login.php. It works when i use the DOCUMENT_ROOT before it but not like this. This is my problem, i dont know what im doing exactly so when i change the sturcture to solve one problem i get another problem somewhere else.


  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    Images are probably best linked to as posted by Serbian.
    Includes tend to be library type files whose functions or classes you want to include in your program.

    Try

    include '/includespath/includefile.php';

    in your PHP.

    Change names as required.
    If your webserver supports PHP it already knows where $_SERVER is.
    In this example the includes directory is directly off the "root".


  • Registered Users Posts: 673 ✭✭✭Bananna man


    is_that_so wrote:
    Images are probably best linked to as posted by Serbian.
    Includes tend to be library type files whose functions or classes you want to include in your program.

    Try

    include '/includespath/includefile.php';

    in your PHP.

    Change names as required.
    If your webserver supports PHP it already knows where $_SERVER is.
    In this example the includes directory is directly off the "root".

    That gives me problems if im on a page in a subfolder though, if i have my links in an includes file when im not in the root folder i get problems.


  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    That gives me problems if im on a page in a subfolder though, if i have my links in an includes file when im not in the root folder i get problems.

    Can you post some code to show exactly what you mean?


  • Advertisement
  • Registered Users Posts: 673 ✭✭✭Bananna man


    The links are working finr noe with just putting '/mysite/login.php' but i have tried doing the includes in this format also but if i use just:

    <?php include '/ps3-includes/right-column-homepage.php';?>

    or

    <?php include '../ps3-includes/right-column-homepage.php';?>

    its not working, but if i use

    <?php include $_SERVER.'/ps3-includes/right-column-homepage.php';?>

    it does.

    Does anyone know of a good tutorial about this? I have had a look on the php.net site but that didnt help matters and did a search for tutorials in this specific area but couldnt find anything.


  • Registered Users Posts: 32,136 ✭✭✭✭is_that_so


    What does phpinfo(); or print_r($_SERVER); tell you?
    They can give you server settings details.

    Here is a tutorial which may help explain the use of paths for you.


  • Registered Users Posts: 673 ✭✭✭Bananna man


    is_that_so wrote:
    What does phpinfo(); or print_r($_SERVER); tell you?
    They can give you server settings details.

    Here is a tutorial which may help explain the use of paths for you.

    Cheers, i'll have a read of that :)


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    Serbian wrote:
    You should never use $_SERVER; to reference files on your server. You are exposing the filestructure of your machine for a start and it's bad practice.
    In the example where OP included a php script, a user will not see the value for $_SERVER.
    In the example with the image file, it simply won't work if DOCUMENT_ROOT is not the root dir (because browser will need a different path to the file system).

    Either way, I don't see how it exposes the file structure.


Advertisement