xwishmasterx Posted February 2, 2013 Share Posted February 2, 2013 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 More sharing options...
PFMaBiSmAd Posted February 2, 2013 Share Posted February 2, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273951-need-helpinfo-using-include/#findComment-1409704 Share on other sites More sharing options...
xwishmasterx Posted February 2, 2013 Author Share Posted February 2, 2013 Thanks for the answer. It seems what I feared (although it seems logical). I will try to work around it. ty Link to comment https://forums.phpfreaks.com/topic/273951-need-helpinfo-using-include/#findComment-1409706 Share on other sites More sharing options...
PFMaBiSmAd Posted February 2, 2013 Share Posted February 2, 2013 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. Link to comment https://forums.phpfreaks.com/topic/273951-need-helpinfo-using-include/#findComment-1409707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.