require and include not working.

I have a web site that we moved to a new server. The commands require_once, require, inlcude and include_once no longer seem to work on the new server. Any functions defined in a .php file and then loaded with require_once are not available. The same code works on 3 other PHP implementations. What setting are we over looking on the new PHP implementation that is causing this?

Sounds like there are absolute paths specified to included files. There is no reason for standard php functions (such as require_once and include) to not working on new server. You just need to check paths to the included files, and correct them to match locations on new server.

It sounds like your file path is wrong. Place your code here so we can better see what’s wrong with it.

As long as your syntax follows this format, include(‘myfolder/myfiles.php’); it should work. And make sure you do not mispell anything like you did below…

The files I am trying to require are in the same directory as the file calling them.

login.php has a require for mainAllFuncs.php which has sub requires in it. It has require for startupFuncs.php which contains mySessionVars(); subroutine.

This same code works on 2 other PHP systems (Windows and Linux). It was copied to this system but does not work on it.

I tried both

require_once(‘mainAllFuncs.php’); and require_once(’./mainAllFuncs.php’); but neither seem to work. An absolute path of require_once(’/local/apps/opsdev/htdocs/mainAllFuncs.php’); does not wiork either .

Sample:

login.php snippet

<?php session_start(); $fname = $_SESSION['fname']; echo "fname = $fname

\n"; require_once('mainAllFuncs.php'); //mySessionVars(); is in file startupFuncs.php which is called from mainAllFuncs.php mySessionVars(); .......... ?>

mainAllFuncs.php code

<? require_once('startupFuncs.php'); require_once('myDBFuncs.php'); require_once('myHTMLFuncs.php'); require_once('opsHTMLFuncs.php'); require_once('opsMenu.php'); require_once('modUserVarFuncs.php'); require_once('addUserVarFuncs.php'); require_once('pwFuncs.php'); function doHeaderFuncs() { session_start(); mySessionVars(); // myZAMMVars(); isUserLoggedOn(); } ?>

startupFuncs.php code snippet:

<? function mySessionVars() { //****************Log-On User Session Variables if ( !isset($_SESSION['badcount'])) { $_SESSION['badcount']=0; } $badcount = $_SESSION['badcount']; ..... ?>

I changed the start of the files from <? to <?php and it now works.

What setting in php copntrols that so I can have the UNIX admin set it correctly.

Thanks for all your input.

It is not a good idea to allow short tags. They can be ambiguous; plus when moving to a different server, you might find that they are not enabled and you might not be able to get it changed. It is safer to just use the full tags: “<?php”.

Having said that, the setting is in the php.ini file. Its name is “short_open_tag” (see the manual at: http://us.php.net/manual/en/ini.core.php#ini.short-open-tag)

Sponsor our Newsletter | Privacy Policy | Terms of Service