I have a website that is running on WordPress. In the document root of this site, I have a directory in which I test PHP scripts unrelated to my WordPress installation. I notice that whenever I require or include a file that indeed exists, I get a 404. If I comment out the require statement, all is well. At first, this was because of syntax errors. But I cleaned it up and am no longer getting anything in the error_log file. What gives?
EDIT: found this in my main error_log: malformed header from script. Bad header=X-UA-Compatible: ide.php. I’ve never had a problem with this on other Apache servers.
Below is the offending script:
ide.php
<?php
require_once 'config.php';
if (isset($_SESSION['username'])) {
if (isset($_POST['command'])) {
if ($_POST['session'] == '@') {
session_destroy();
header('Location: /area51/ide.php');
} else {
echo 'None';
}
} else {
$smarty->assign('version', shell_exec("/home1/tylercro/local/python3/bin/python3 -c \"import sys;print('Python', sys.version)\""));
$smarty->display('ide.tpl');
}
} else {
if (isset($_POST['username']) && isset($_POST['password'])) {
if ($_POST['username'] == 'user' && $_POST['password'] == 'password') {
$_SESSION['username'] = $_POST['username'];
}
header('Location: /area51/ide.php');
} else {
$smarty->display('ide-login.tpl');
}
}
?>
config.php
<?php
error_reporting(E_ALL);
session_start();
if (!headers_sent()) {
header('X-UA-Compatible: chrome=1');
header('Content-Type: text/html; charset=UTF-8');
}
require_once 'Smarty-3.1.8/Smarty.class.php';
$smarty = new Smarty();
$smarty->setTemplateDir('Smarty-3.1.8/templates/');
$smarty->setCompileDir('Smarty-3.1.8/templates_c/');
$smarty->setCacheDir('Smarty-3.1.8/cache/');
$smarty->setConfigDir('Smarty-3.1.8/configs/');
?>
It was a header issue. I had some syntax errors in the headers that I was sending out.