xcandiottix Posted June 15, 2010 Share Posted June 15, 2010 I have an HTML page with a page include. The included page is php. How can I get the php to know which html page I have open? For example: cars.html boats.html include.php if I browse to cars.html I want: the php include knows i'm on 'cars.html' and the include echos "You're looking at the cars page" which shows up on cars.html OBVIOUSLY i can make cars.html a cars.php and solve the issue by passing a variable along but that is not an option, cars.html must stay html. I tried to put this in the include: function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } put that returns the name of my php file... not my html file. Any help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/ Share on other sites More sharing options...
Cagecrawler Posted June 15, 2010 Share Posted June 15, 2010 Assuming you're including the page using Server Side Includes (SSI), I'm not aware of a way to. With SSI, the web server processes the included script and includes the output, rather than including the PHP file itself. If the reason it must be html is to maintain links, you can use .htaccess to transparently change any cars.html requests to cars.php ones. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072175 Share on other sites More sharing options...
xcandiottix Posted June 15, 2010 Author Share Posted June 15, 2010 I'm not too up on .htaccess ... here's why i can't switch the .html out. The way the the site is navigated allows for someone to type www.site.com/user/johndoe ... since there's no extension the sever defaults to .html and completes the url as www.site.com/user/johndoe.html. If the extension is written as .php and the file is a .php a 404 error is produced when typing www.site.com/user/johndoe even though www.site.com/user/johndoe.php exists. Hope that makes any sense. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072179 Share on other sites More sharing options...
Cagecrawler Posted June 15, 2010 Share Posted June 15, 2010 That's easily solvable with .htaccess. Google "htaccess clean urls" for examples of how to hide the extension and change the default extension. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072189 Share on other sites More sharing options...
xcandiottix Posted June 15, 2010 Author Share Posted June 15, 2010 Sweet action, i'll look right into. By the way in the mean time I got this far on a different route: in reference to my original example: cars.html: <!--#set var="current" value="$SCRIPT_NAME"--> <!--#echo var="current"--> echos: cars.html I'm not sure but could I turn the var 'current' into a global variable that php could access? Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072192 Share on other sites More sharing options...
jamesxg1 Posted June 15, 2010 Share Posted June 15, 2010 Have a look into $_SERVER['PHP_SELF'] James. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072197 Share on other sites More sharing options...
xcandiottix Posted June 15, 2010 Author Share Posted June 15, 2010 Feeling good. HTML page: <!--#set var="Current" value="$SCRIPT_NAME"--> <!--#include virtual="/reportvariable.php" --> PHP include: <?php echo $_SERVER['Current'];?> When viewing the HTML page: thePageImLookingAt.html Awesome. Thanks guys. Link to comment https://forums.phpfreaks.com/topic/204796-in-need-of-some-brilliance/#findComment-1072200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.