Hi.
I'm trying to make a simple "Last modified: date"-script that can be included in all the web-pages across our entire network. This is not easy, however...
<?php
//filename: date_footer.php
// English date?
if (isset($lang) and ($lang=="eng")) {
setlocale ("LC_ALL", "en_EN");
echo strftime("%e %B %Y %H:%M", getlastmod());
}
// Default is norwegian date
else {
setlocale ("LC_ALL", "no_NO");
echo strtolower(strftime("%e. %B %Y %H:%M", getlastmod()));
}
?>
Then I include date_footer.php in all webpages like this:
<?php include "http://www.someserver.net/date_footer.php"; ?>
or
<?php include "http://www.someserver.net/date_footer.php?lang=eng"; ?> for english date.
Now, this works fine as long as the file that includes date_footer.php is in the same directory as date_footer.php. But if i have a file at www.someserver.net/info/something.php that includes http://www.someserver.net/date_footer.php, the script returns the last modified date of the date_footer.php file, not the something.php file like it is supposed to...
I've tried solving this using filemtime() but this func don't work on remote files.
I also tried to solve it using a combination of getlastmod() and filemtime() and checking wether the file is in the root directory - use getlastmod() or if the file is in a directory further down - use filemtime(basename($PHP_SELF)). Like this:
<?php
//something.php
global $filename_and_path;
$filename_and_path = $PHP_SELF;
include "http://www.someserver.net/date_footer.php";
?>
<?php
//date_footer.php
if ($filename_and_path == "/".basename($filename_and_path)) {
// this means the file is on the root-level
// English date?
if (isset($lang) and ($lang=="eng")) {
setlocale ("LC_ALL", "en_EN");
echo strftime("%e %B %Y %H:%M", getlastmod());
}
// Default is norwegian date
else {
setlocale ("LC_ALL", "no_NO");
echo strtolower(strftime("%e. %B %Y %H:%M", getlastmod()));
}
}
else {
// the file is in a directory
$filename = basename($filename_and_path);
// English date?
if (isset($lang) and ($lang=="eng")) {
setlocale ("LC_ALL", "en_EN");
echo strftime("%e %B %Y %H:%M", filemtime($filename));
}
// Default is norwegian date
else {
setlocale ("LC_ALL", "no_NO");
echo strtolower(strftime("%e. %B %Y %H:%M", filemtime($filename)));
}
}
?>
The $filename_and_path variable should be accessible in date_footer.php since it is a global variable. But it seems that a global variable can't be set because the date_footer.php is included via URL, which, in turn, makes the scope for the global variable the entire internet. Well, this makes sense, but how the h*** am I going to solve my problem? :/
Any help is greatly appreciated...