When i run this code on a local server it works fine, but if i run it on my domain it does not work, and i dont understand why.
I have tried to comment out sections on the page and it seems to crash when i define the 'siteTitle()' function. Here is the code up until the point it crashes:
index.php
<?php
include('functions.php');
varSet();
if (include('pages/'.$pageID.'.php')) {
// DO NOTHING
} else {
require('404.php');
}
?>
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="utf-8" />
<title><?php siteTitle('Obsidian.no', true, ' | '); ?></title>
functions.php
<?php
// Functions requierd by ~/index.php
function isOnline() {
if (preg_match('/::1$/', $_SERVER['SERVER_ADDR']) || $_SERVER['SERVER_ADDR']=='127.0.0.1') {
return 0;
} else if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $_SERVER['SERVER_ADDR'])) {
return 1;
} else {
return false;
}
}
function varSet() {
// User-defined Globals goes here:
// Set IP-variables
$cIP = $_SERVER['HTTP_CLIENT_IP'];
$xIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
$rIP = $_SERVER['REMOTE_ADDR'];
if (!empty($cIP)) {
$usrIP = $cIP;
} else if (!empty($xIP)) {
$usrIP = $xIP;
} else {
$usrIP = $rIP;
}
// Set $root
if (isOnline()) {
$root = $_SERVER['DOCUMENT_ROOT'].'/design8';
} else {
$root = $_SERVER['DOCUMENT_ROOT'];
}
// Set $pageID
if (isset($_GET['pageid'])&&!empty($_GET['pageid'])) {
$pageID = $_GET['pageid'];
} else {
$pageID = 'home';
}
// Make Globals
$GLOBALS['cIP'] = $cIP;
$GLOBALS['xIP'] = $xIP;
$GLOBALS['rIP'] = $rIP;
$GLOBALS['usrIP'] = $usrIP;
$GLOBALS['root'] = $root;
$GLOBALS['pageID'] = $pageID;
}
function siteTitle($title, $displayPageName = true, $separator = ' | ') {
global $root;
global $pageID;
if (get_required_files()['2']==$root.'/404.php') {
echo($title.$separator.'Page not found (Error: 404)');
} else {
if ($displayPageName) {
echo($title.$separator.ucwords($pageID));
} else {
echo($title);
}
}
}
I am aware that not all html and php tags are closed here, but thats because this is just the parts that run before the crash. If the 'siteTitle()' function is not commented out in functions.php, it crashes at 'require('functions.php')'. And if it is in comment it obviously crashes when the function is called in index.php.
However the site runs perfectly on MAMP localhost, but not from my domain hosted by one.com.
Thanks for any answers !
(404.php is irrelevant, as it does not contain anything)
The PHP version on the server is 5.6.3, and 5.6.2 on the localhost.
$files=get_required_files();then use$files[2]in the condition