Jump to content

Advanced PHP Includes


redwall_hp

Recommended Posts

I use PHP includes for my site. I have a header file which contains everything up to the main content. Then I ahve the footer file which is everything down from the content to the </html> tag.I would like to be able to have code in the header file which checks to see what the current page is (the current page. not the included header file). Whenever I try to, it tells me the current page is header.php rather than the actual page being viewed (ex. index.php which has php include statements pointing to the header and footer files). I'd also like to be able to pass variable from the index page to one of the included one. Which doesn't work as expected. I'd like to set a variable on the index to what I want the page title to be. Since the title tag for the page is in the header.php file, it should read the variable and echo the variable inside the title tag. This doesn't work as expected and it doesn't do anything.

Link to comment
Share on other sites

I use PHP includes for my site. I have a header file which contains everything up to the main content. Then I ahve the footer file which is everything down from the content to the </html> tag.I would like to be able to have code in the header file which checks to see what the current page is (the current page. not the included header file). Whenever I try to, it tells me the current page is header.php rather than the actual page being viewed (ex. index.php which has php include statements pointing to the header and footer files). I'd also like to be able to pass variable from the index page to one of the included one. Which doesn't work as expected. I'd like to set a variable on the index to what I want the page title to be. Since the title tag for the page is in the header.php file, it should read the variable and echo the variable inside the title tag. This doesn't work as expected and it doesn't do anything.
you should be able to do something like $_SERVER['PHP_SELF']; if that returns header.php then you should check that the code in header.php actually has start and end tags for php (ex <?php ?> ) the extension is alredy .php so that shouldnt be causing the problemfor the variable thing, i havent been able to do that myself. some other helper could help. send a pm to justsomeguy if he hasnt alredy posted here.
Link to comment
Share on other sites

If you want to check for the page, both $_SERVER["PHP_SELF"] and $_SERVER["SCRIPT_NAME"] will refer to the root script (not the included file). __FILE__ always refers to the current file being executed, on the other hand. If all else fails, you can check $_SERVER['URL'] and either parse up the URL and get the filename, or just search for a specific filename.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...