jnnewton Posted February 15, 2009 Share Posted February 15, 2009 hello, i am trying to move a function out of a page and into a functions.php file in a functions folder. i added .:\eclipse workspace\homepage\functions to the php.ini file, and am getting this: Notice: Use of undefined constant template - assumed 'template' in D:\eclipse workspace\homepage\index.php on line 37 Notice: Use of undefined constant top_nav_menu - assumed 'top_nav_menu' in D:\eclipse workspace\homepage\index.php on line 37 Warning: Division by zero in D:\eclipse workspace\homepage\index.php on line 37 Notice: Use of undefined constant php - assumed 'php' in D:\eclipse workspace\homepage\index.php on line 37 Warning: include(../php) [function.include]: failed to open stream: No such file or directory in D:\eclipse workspace\homepage\index.php on line 16 Warning: include() [function.include]: Failed opening '../php' for inclusion (include_path='.:\eclipse workspace\homepage\functions ; The root of the PHP pages, used only if nonempty. ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root ; if you are running php as a CGI under any web server (other than IIS) ; see documentation for security issues. The alternate is to use the ; cgi.force_redirect configuration below doc_root = ; The directory under which PHP opens the script using /~username used only ; if nonempty. user_dir = ; Directory in which the loadable extensions (modules) reside. extension_dir = c:/wamp/bin/php/php5.2.8/ext/ ; Whether or not to enable the dl() function. The dl() function does NOT work ; properly in multithreaded servers, such as IIS or Zeus, and is automatically ; disabled on them. enable_dl = On ; cgi.force_redirect is necessary to provide security running PHP as a CGI under ; most web servers. Left undefined, PHP turns this on by def in D:\eclipse workspace\homepage\index.php on line 16 This is way beyond me, i need a little guidance. here is my php files homepage/index.php <?php require_once("functions/functions.php") or die("Couldn't load myfile"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="style/test1.css" type="text/css"></link> <link rel="stylesheet" href="template/top_nav_menu/top_nav_menu.css" type="text/css"></link> </head> <body class="index"> <div id="container"> <div id="top"> <div id="header"> <img src="images/logo.png"/> </div> </div> <div style="background-image: url(images/center_tile.gif);"> <?php abs_include(template/top_nav_menu.php)?> </div> <div id="leftnav"> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut. </p> </div> <div id="content"> <h2>Index.php</h2> <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. </p> <p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. </p> </div> <div style="background-image: url(images/center_tile.gif);"> <?php abs_include(template/footer.php)?> </div> </div> </body> </html> homepage/functions/functions.php <? function abs_include($file) { /* $file is the file url relative to the root of your site. Yourdomain.com/folder/file.inc would be passed as "folder/file.inc" */ $folder_depth = substr_count($_SERVER["PHP_SELF"] , "/"); if($folder_depth == false) $folder_depth = 1; echo(str_repeat("../",folder_depth-1) . $file); include(str_repeat("../", $folder_depth - 1) . $file); } ?> thanks for any help Link to comment https://forums.phpfreaks.com/topic/145242-php-include-for-functions-folder/ Share on other sites More sharing options...
wildteen88 Posted February 15, 2009 Share Posted February 15, 2009 All file paths need to be wrapped in strings: For example <?php abs_include(template/top_nav_menu.php)?> Should be <?php abs_include('template/top_nav_menu.php')?> And <?php abs_include(template/footer.php)?> Should be <?php abs_include('template/footer.php')?> Link to comment https://forums.phpfreaks.com/topic/145242-php-include-for-functions-folder/#findComment-762684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.