Jump to content

Need help/info using "include"


xwishmasterx

Recommended Posts

Hello

 

I am getting some errors when trying to build up a page using include ( Parse error: syntax error, unexpected $end in..)

 

I know why and where this is happening, but not why it won't work (pretty sure I've done it in the past), anyway more details:

My page is a simple build

 

include header.php

page stuff

include footer.php

 

 

The problem is the header checks if the user is logged in and such and ends with:

if($_SESSION['loggedin'] != TRUE) {
header("Location: /index.php?=loggedout");
}else{
?>

 

Now the last "else" statement isn't closed which gives the error, but why can't I close it in the footer? like so:

 

<?php
}
?>

 

Any info would be appreciated ;)

Link to comment
https://forums.phpfreaks.com/topic/273951-need-helpinfo-using-include/
Share on other sites

You cannot split the syntax for any one statement between files. Any language statement that you open, must be closed in the same file.

 

The main file is parsed, tokenized, and interpreted when the page is requested. Any induced code is parsed, tokenized, and interpreted when the include statement is executed.

For your specific usage, you should use a exit; statement after the header() redirect to stop execution of the remainder of the code on the page. You don't need to surround everything else (lol, no pun intended) on the page in an else {} statement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.