Start PHP IF statement in header and finish in footer?

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
dsontag
Posts: 3
Joined: Thu Feb 02, 2012 5:56 pm

Start PHP IF statement in header and finish in footer?

Post 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?
Klemen
Site Admin
Posts: 10145
Joined: Fri Feb 11, 2005 4:04 pm

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

Post 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.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
dsontag
Posts: 3
Joined: Thu Feb 02, 2012 5:56 pm

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

Post 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.
dsontag
Posts: 3
Joined: Thu Feb 02, 2012 5:56 pm

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

Post 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.
Klemen
Site Admin
Posts: 10145
Joined: Fri Feb 11, 2005 4:04 pm

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

Post 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!
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply