Jump to content

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 ;)

Edited by xwishmasterx
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.