I am having problems with PHP include. I do have a script that generates pages on the fly when requested by a user or a search engine. I need to include some extra stuff and are using the PHP include function to pull the code in. The problem is that the include (see bold code) apparently does not get executed. Now for testing I pasted my code from the file I was trying to include directly into the page and it executes just fine. What could be the cause for this? The file permissions on the include file are normal. Other includes are working fine. Thanks. Christoph
<?php include('http://www.mydomain.com/subfolder/additionalfile.php'); ?> try <?php include("http://www.mydomain.com/subfolder/additionalfile.php"); ?> I use this <?php include("../includes/leftnav.php"); ?>
I've had problems with include() using absolute paths. Try using relative paths like <?php include('../subfolder/additionalfile.php'); ?> with the correct path to the file and it should work.
Just a heads up: including via HTTP doesn't do what you would expect it to do as the server parses the PHP first. BrianR2: I find it interesting that you've had problems using absolute paths... the only problems I've had was with relative ones (for example, including a file in one directory which includes another file where a file with that name exists in multiple directories). I use a 'combination' of relative paths and dirname( __FILE__ ): that way I essentially get to use relative paths as I would expect them to work.
maybe it depends on the server settings. i thought i had used absolute paths before without problems.
I agree that absolute paths aren't perfect: moving to different servers and so on requires changes to files. That's why I use that combination as it basically gives me 'dynamic absolute' directories.