Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: if ($Name=='ProxiedIP') leads to 500 (Internal Server Error)

This may be too obscure of an question, but I've been troubleshooting a baffling server error for hours and have pinned it down to the most bizarre issue; at this point I just want to know if anyone has ever had something similar occur, or might have any insight into what might possibly be happening.

The following line of code is triggering the error:

if ($Name=='ProxiedIP') { return true; }

This version runs without any problem at all:

if ($Name=='proxiedIP') { return true; } 

It seems like somehow the token 'ProxiedIP' is fouling something up, but I cannot even think of how a string literal would be translated by the parser in a way that could hang the server up like this. BTW, I know for certain that $Name!='proxiedIP' and $Name!='ProxiedIP'.

Here's the entry in the apache error log:

[Fri Jan 18 18:15:12.924419 2013] [core:error] [pid 27676:tid 3427232831232] [client 12.345.67.890:34482] Premature end of script headers: index.php, referer: http://mySite.com/

I searched for 'ProxiedIP' as a keyword for every component that I can think of on my system and I'm coming up with nothing. The more imperative question for me though is how a string could somehow have this impact in a comparison check. Any ideas?


Also noteworthy that the PHP error log is completely silent about it. I'm enabling error output at the top of the page, but the script never finishes loading so that may be a factor. Here's how I'm setting it:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Because the code worked here, it seems more likely that it could be something specific to the platform implementation. I'm running this on an instance of Gandi.net's 'Simple Hosting' service, which runs Varnish for application acceleration. It may also be worth mentioning that the code is being loaded in an iframe in a separate domain.

I am also doing some intensive work with the headers, and this seems like the greatest potential source of the problem, although the strange thing as far as I'm concerned is the way the error is being triggered. Also, there's no common header that I'm aware of called 'ProxiedIP', although that use conflict is the only thing that seems like it could make sense so far. Regardless, I don't see it.

To me, the real item of relevance is the mere fact that a string comparison is crashing the server. I've been programming in PHP for over 10 years and I have never had anything like this happen before. I'm trying to understand the logistics behind how it could even happen.


Update: I've tried the following variation, and it still produces the same result:

if ($Name === (strtoupper("p").'roxiedIP')) { return true; }

It was asked whether I would post the full code, but the script for the iframe side is 1400+ lines long so that's not really feasible. I'm adapting the segment in question to try running it in a new script though and will post the results.

like image 695
jtrick Avatar asked Jan 18 '13 23:01

jtrick


2 Answers

I think the problem is with the variable $Name. Check whether it is getting assigned properly. Also check the code after if statement which is causing the problem.

like image 83
nbbk Avatar answered Sep 30 '22 16:09

nbbk


Actually, I think your problem lies in the calling function, i.e. depending on the return value it does something "stupid" and PHP crashes. Try replacing the if() with a hard return true or return false and see what happens.

like image 26
JvO Avatar answered Sep 30 '22 16:09

JvO