phpincludewebserver

require_once function causing a server error


I am trying to use the require_once(""); function in php, and it is causing a server error whenever it is used. I know I am using the correct path because I have checked my file directory many times and have been following a video tutorial as well when coding this php code. Any ideas to why I am getting this server error?

       <?php
            require_once("../../includes/session.php");
       ?>

The page calling this function is in a folder that shares folders - two sub-folders away from session.php if that makes sense.

This file is index.php, which is in public/admin. This page calling require_once is in public/admin/index.php, and the folder they both share is photo_gallery.

The error is: HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

All the debugging I have done is echo a hello statement before calling require_once and after require_once and when I posted hello after nothing was outputted

This is the error I receive when checking my error log:

[08-Aug-2012 11:01:04] PHP Parse error: syntax error, unexpected '{' in /home3/visittom/public_html/photo_gallery/includes/session.php on line 47


Solution

  • require and include paths are relative to the file where they are declared, not necessarily the page that is loaded by the user. So if your index.php includes another page which contains the require_once you may run into problems.

    Also, check the web server error logs which should provide more detail about that 500 error.