Jump to content

In need of some brilliance...


xcandiottix

Recommended Posts

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

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.

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.

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?

8) 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.