Jump to content

Unreliable URI replacement? - dirname / str_replace / url_array explode


freak9999

Recommended Posts

I'm using ForceType and the code below to change the URI address of included files to replace the ?file=filename with /directory/filename (aka 'search friendly URLs')

[code]
<?php
global $REQUEST_URI;
global $SCRIPT_NAME;
$path = $SCRIPT_NAME;
$base_href = dirname($path);
$vars = str_replace($path, "", $REQUEST_URI);
$array = explode("/",$vars);
$num = count($array);
for ($i = 0 ; $i < $num ; $i++) {
        $url_array["arg".$i] = $array[$i];
}
$page = $url_array["arg1"];
$page2 = $url_array["arg2"];
?>

[/code]


Then:
[code]
<?php
$content = "$page/"
  . $page2
  . ".php"; 

if (!file_exists($content)) {
$content = "inc/error.html";
include($content);
} else {
include($content);
}

?>

[/code]

The file to be included is in a folder - directory1
It is called test_include
The file with the above code is called initialfile (The ForceType has been set on this)

I'm finding this usually works but if I copy the exact same file (test_include.php) to a different folder - directory2 the file (to be included) cannot be found. I have checked the file exists and tried numerous variations of folder name or file name and cannot work out any pattern to why it sometimes works and sometimes not.

Can anyone advise if there are any conditions that stop this from working.

How can this be?
Many thanks, mat

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.