Hi there,
I have made this code to detect what section a page is being displayed in and include an apropriate file.
The problem is that if I set the variable $page_check to a file on our server to test it, every thing works as it should.
But then when I place the script in a template file where the $page_check variable is set to $phpself - when loading a page with the script on I get firefox giving me a download box to download the current page file.
So I figure I cant request a page to fopen a url which is the same url the script is on?
So my question is how do I set up this script so it looks at its own source code, does a preg_match to find out what section its in?
<?php
// the adress of the file to read
$domain = 'http://www.domain.com';
$thispage = $PHP_SELF;
$page_check = "$domain$thispage";
$fp = fopen($page_check, 'r') or die('Unable to open file '.$page_check.' for reading');
$cont = '';
while(!feof($fp))
{
$buf = trim(fgets($fp, 4096));
$cont .= $buf;
}
preg_match('/<a name="sectiontop" id="sectiontop"><A class="breadcrumbs" HREF="(.*?)">/i', $cont, $match);
if ( $match[1] == "books_multimedia.htm")
{
include("/home/public_html/booksnav.php");
}
if ( $match[1] == "products.htm")
{
include("/home/public_html/productsnav.php");
}
if ( $match[1] == "music.htm")
{
include("/home/public_html/musicnav.php");
}
else
{
include("/home/public_html/shopnav.php");
}
?>