POST redirect: different behavior in index.php vs included files


#1

Any ideas on what could cause this first example to work and the second example to fail? I got as far as determining that the behavior depends only on where I stick the one line of code that triggers the redirect: it works in my main index.php file, and it fails when I put it at the end of the included code in another file. I’m using Apache webserver, I’ve got the files owned apache:apache and chmod 664, I changed the security context:
sudo chcon -R system_u:object_r:httpd_sys_content_t:s0 /var/www/secure/dev/{all my projects}

Example 1: this works

within index.php:
$app->post(’/add/template’, function ($request, $response, $args) {
require_once ‘…/app/routes/add_template__post.php’;
return $response->withStatus(303)->withHeader(‘Location’,$url);
});

within ./app/routes/add_template__post.php
(some stuff)

Example 2: this fails

within index.php:
$app->post(’/add/template’, function ($request, $response, $args) {
require_once ‘…/app/routes/add_template__post.php’;
});

within ./app/routes/add_template__post.php
(some stuff - exacty the same)
return $response->withStatus(303)->withHeader(‘Location’,$url);


#2

I should clarify what I mean by “it fails.”

What I observe is that my web browser does not redirect- just has empty content. My Apache access logs show a 200 OK response, and this is consistent with what I see using ‘ngrep’ to sniff the traffic from command line on the webserver.

Edit: I have confirmed this behavior change is repeatable with simply moving the location of a single line of code, from the last statement in an included file to the first line after the included file in the $app->get closure that calls it. Other commands in the included file are verified to run, so it is not a simple file permission or ownership thing.