Wednesday 15 June 2011

php - Functions stop working when file included with root path (leading slash) -


My PHP files included in my original directory header. Header.php includes functions.php I'm adding new pages in a subdirectory, so I added slash leading to all my links in header.php: CSS, menu items and later include in functions.php. CSS and menu items work fine on this page in the sub-directory, but the functions do not work. There is no link in the function that requires a major slash.

Is the combination of included and requires a major slash to modify the function?

From a page in the root directory: include

  ('header.php');   

From a page in the subdirectory:

 Include  ('/ header.php');   

From header.php: Include

  ('/ functions.php');   

and the function that no longer works (called from the pages in the root directory or subdirectory):

  function show_date ($ array_name) {if ( Date ("FJ, Y", "Straighttoem", "UF J", Straotomem ($ array_name ["Exhibit_Open"])) == Date ("YFJ", strotomom ($ array_name ["exhibit_close"])) ) ($ Array_Name ["exhibit_open"])); } {$ First_date_format = "FJ, Y"} ("Y", Stratom ($ array_name ["exhibit_open"]) = date ("Y", strotom ($ array_name ["exhibit_close"])); "Date" ("FJ, Y", Stratomem ($ array_name ["exhibit_close"]));} Otherwise (date ("F"), then the date of the echo ($ first_data-format, strtoomem ($ array_name ["exhibit_open"]) "$ String_name [" exhibit_open "]) = date (" f ", strotomem ($ array_name [" exhibit_close "]))) {$ first_date_format =" FJ "; resonance date ($ first_data-format, strotomom ($ Array_name ["exhibit_open"])) "-" date ("FJ, Y", ST "$ (Date $ array_name [" exhibit_close "]);} and {$ first_date_format =" j "; resonance date (" FJ ", strotomeme ($ array_name [" exhibit_open "]))" - "Date ($ first_date_format, Date ("Array_Name [" exhibit_close "]  

Just you know, if you are going to the php pages for which you are requesting yourself Request other pages, it can be beneficial to use include instead of need_once . This will not have any such page, which includes, repeat yourself and you are not worried about accidentally adding anything more than once.

It is being said ... When you request a page root directory, it will request header.php in the root directory which will act as the requests in the root directory. Php. However, if you request a subdirectory, the header.php will reference in the ../ header.php root directory, but that entire file will be included, and then its sub-directory The php page will end up in an attempt to include /functions.php , it will need to request the ../work.php , but from everything in the root directory Will stop working.

I suggest setting a variable in header.php with the lines of $ root = $ _SERVER ['DOCUMENT_ROOT']; Then, header.php should include all the ($ root. "/ Functions.php");

$ _ SERVER ['DOCUMENT_ROOT'] will get you the root URL in the root, so you can be sure that you are referring to the correct location It does not matter if you are requesting header.php from

No comments:

Post a Comment