Script not handling path correctly

software development

#1

I have the following code in my index.php. One site handles it correctly. The other does not. They are both sub-domains.
The script runs fine on the site medinfo.venuemaster.net but bombs out on hisa.venuemaster.net

The index.php contains the following

<?php require_once("stuff/config.php"); "stuff/header.html"; $file = 'content/'.$_GET['page'].'.html'; if (!isset($_GET['page'])) $file='main.html'; if (!file_exists($file)) header('Location: '.$CFG->serverName.$CFG->sitePath.'home'); include 'stuff/main.html'; ?>

The config.php contains the following code.

<?php $CFG->sitePath = ''; $CFG->serverName = 'http://'.$_SERVER['SERVER_NAME'].'/'; ?>

Any help would be appreciated.


#2

[quote]I have the following code in my index.php. One site handles it correctly. The other does not. They are both sub-domains.
The script runs fine on the site medinfo.venuemaster.net but bombs out on hisa.venuemaster.net[/quote]
Sorry, ‘bombs out’ is not enough information. If you are getting error messages, let us know what they say. Otherwise revise the code and either reduce it to test case or add some debug statements. Also make sure you are running the same version PHP, include a call to phpinfo() for both domains. Latest version is 5.2.6

You do realize the code you posted contains an obvious mistake, right?require_once("stuff/config.php"); "stuff/header.html"; $file = 'content/'.$_GET['page'].'.html';Though that would only result in not displaying the header.

And where is main.html? Your script assumes it is in the same directory as the script, but the other files are in ‘stuff’ or ‘content’. Maybe you misplaced the files.

And it case you don’t see the problem, let’s re-factor your code.

// Path to configuration code define('CONFIG_PATH', 'stuff/'); // Path to header HTML define('TEMPLATE_PATH', 'stuff/'); // Path to page contents define('CONTENT_PATH', 'content/'); // run configuration code require_once(CONFIG_PATH . "config.php"); // get the name of the page to use if (!isset($_GET['page'])) { $page = 'main'; } else { $page = $_GET['page']; } // get the path of the page file $file = CONTENT_PATH . $page . '.html'; // redirect if it doesn't exist if (!file_exists($file)) { header('Location: '.$CFG->serverName.$CFG->sitePath.'home'); } else { // include header HTML include(TEMPLATE_PATH . "header.html"); // include page include(CONTENT_PATH . $file); }
Tip. Write it out in English first. Helps avoid doing things out of order.

:cool: openvein.org -//-