liquinas Posted July 31, 2008 Share Posted July 31, 2008 Hello again! I'm trying to pull an include on all files on a site. I'm trying to get all files in the root directory as well as all files inside folders pull the same file. I came up with this: <?php include('http://'.$_SERVER['SERVER_NAME'] . '/inc/php_header.php'); ?> <html> <head>123</head> <body> The phone number is <?php echo "$phone"; ?> </body> </html> All that's in the include file is this: <?php $phone = "555-555-5555"; ?> Problem is that $phone won't echo, however it does just fine with a regular include line: include('inc/php_header.php'); Is there a better way to do this? Am I doing something wrong? Any help appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/117640-root-include-and-passing-variable/ Share on other sites More sharing options...
DarkWater Posted July 31, 2008 Share Posted July 31, 2008 When you access a file through the http:// protocol, PHP uses its HTTP wrapper to access the page. It's including the output of the file, of which there is none. Try: include($_SERVER['DOCUMENT_ROOT'] . 'inc/php_header.php'); Link to comment https://forums.phpfreaks.com/topic/117640-root-include-and-passing-variable/#findComment-605072 Share on other sites More sharing options...
liquinas Posted July 31, 2008 Author Share Posted July 31, 2008 Thanks for the reply DarkWater. If I use include($_SERVER['DOCUMENT_ROOT'] . 'inc/php_header.php'); It goes to htdocs which isn't really the root dir (site pool). Which is why I can use include('../inc/php_header.php'); because the files in the root dir then try to pull from one level above. Any ideas? Link to comment https://forums.phpfreaks.com/topic/117640-root-include-and-passing-variable/#findComment-605078 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.