redwall_hp Posted September 4, 2006 Share Posted September 4, 2006 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 More sharing options...
SFB Posted September 4, 2006 Share Posted September 4, 2006 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 More sharing options...
redwall_hp Posted September 5, 2006 Author Share Posted September 5, 2006 the tags are there.I got the passing variables correct. Insted of mydomain.com/header.php in the include statement, you use ./header.php Link to comment Share on other sites More sharing options...
justsomeguy Posted September 5, 2006 Share Posted September 5, 2006 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 More sharing options...
redwall_hp Posted September 7, 2006 Author Share Posted September 7, 2006 Here's what I'm trying to do:I want to have page (lets call it index.php) that has includes pointing to header and footer. Header should be able to check to see what page is trying to include it (is it index? or not) and react accordingly. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 7, 2006 Share Posted September 7, 2006 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). Link to comment Share on other sites More sharing options...
redwall_hp Posted September 7, 2006 Author Share Posted September 7, 2006 thanks. It seems to work. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now