Page 1 of 1

Start PHP IF statement in header and finish in footer?

Posted: Thu Feb 02, 2012 6:06 pm
by dsontag
Script URL: Intranet (unavailable outside DMZ)
Version of script: 2.1
Hosting company: -
URL of phpinfo.php: N/A
URL of session_test.php: N/A
What terms did you try when SEARCHING for a solution: header, footer, php

Write your message below:
I'm trying to write some PHP if/else to "hide" the helpdesk for two short intervals for a server cutover. I've got the following in header.inc.php (variables are times set earlier in script):

Code: Select all

if (($today > strtotime("-5 minute", $startotg)) && ($today < strtotime("+5 minute", $startotg))) {
	echo 'text message to display to user - moving to backup';
	} elseif (($today > strtotime("-5 minute", $endotg)) && ($today < strtotime("+5 minute", $endotg))) {
		echo 'text message to display to user - return to production';
		} else {
Rest of the code / includes / etc.

AND... in the footer.inc.php file I've the closing tag:

Code: Select all

} // end display messages if between set times.
I've got the start/end of the php if/else above/below the main container table. I've turned debug on and it complains about end of script on line 86 in header.inc.php (and displays a blank page). HUH? I've many many many PHP scripts with headers/footers that have if statements starting in the header and finish in the footer. Why does this not work with the hesk header/footer php files?

NOTE: I have tested the if/else statements in standalone file prior to adding them here - the problem is not with the statements.

Anyone got any ideas?

Re: Start PHP IF statement in header and finish in footer?

Posted: Fri Feb 03, 2012 5:04 pm
by Klemen
It would help if you actually posted the exact error message that the debug throws out.

Now you will need to wait for my reply until 16th I'm afraid as I am out of the country until then.

Re: Start PHP IF statement in header and finish in footer?

Posted: Fri Feb 03, 2012 5:39 pm
by dsontag
I did when I said "I've turned debug on and it complains about end of script on line 86 in header.inc.php (and displays a blank page)" ... my apologies in assuming this would be explanitory enough. Here is the exact line from the script output:

Parse error: syntax error, unexpected $end in /path/to/hdesk/install/inc/header.inc.php on line 86

Pretty much the same info already provided. It's like the script is parsing the header and footer files as separate files from the entire page and not recognizing then all together.

RESOLVED: Start PHP IF statement in header and finish in foo

Posted: Fri Feb 03, 2012 10:12 pm
by dsontag
I actually resolved the problem by keeping the entire if/elseif/else inside the header and then including the footer w/exit(); ...

Code: Select all

if (($today > $startotg - 300)) && ($today < ($startotg + 300))) {
	echo 'sometext';
	include ("path/to/footer");
	exit();
	} elseif (($today > ($endotg - 300)) && ($today < ($endotg + 300))) {
		echo 'othertext';
		include ("path/to/footer");
		exit();
		} else {
			}
This works perfectly.

Re: Start PHP IF statement in header and finish in footer?

Posted: Tue Feb 14, 2012 7:28 pm
by Klemen
Yeh, the problem indeed was that with that code the header.inc.php file wasn't actually a valid PHP file.

Glad to hear you got it working in the meantime!