sixpack434 Posted June 24, 2006 Share Posted June 24, 2006 I have a website with many pages that should not be viewable unless the user is logged on. I am using sessions to know whether the user is logged or not.Ok, instead of going to each PHP file which should be viewable except by logged on users and adding the following code at the top: if(!isset($_SESSION['userName']) && !isset($_SESSION['staff'])){ echo '<p><font color="red" size="+1">Please enter a valid username and password! Click <a href="login.php">here</a> to try again!</font></p>'; } else { I decided to save me allot of time and just include this in the header file, so my header file (header.inc) has the following lines in the end//if the the current page requires authenticationif(basename($_SERVER['PHP_SELF']) != 'index.php' && basename($_SERVER['PHP_SELF']) != 'register.php'&& basename($_SERVER['PHP_SELF']) != 'login.php' && basename($_SERVER['PHP_SELF']) != 'jobs.php' && basename($_SERVER['PHP_SELF']) != 'apply.php' && basename($_SERVER['PHP_SELF']) != 'news.php' && basename($_SERVER['PHP_SELF']) != 'help.php' && basename($_SERVER['PHP_SELF']) != 'contact.php'){ //if the user is not logged on if(!isset($_SESSION['userName']) && !isset($_SESSION['staff'])){ echo '<p><font color="red" size="+1">Please enter a valid username and password! Click <a href="login.php">here</a> to try again!</font></p>'; } else {//else show the page contents?>and all my PHP files would have the following at the top: include('include.inc');However, I'm getting this error: Parse error: parse error, unexpected $end in C:\webroot\site\includes\header.inc on line 116Obviously PHP doesn't like the open { not being closed in the header file, but i have closed them in the footer file. Isn't there any way around this so that I do not have to go to each file and adding the code at the top to check if the user is logged on or not. I thought it'll save me allot of time by just adding the code to the header but unfortunately i'm getting this error. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/12831-parse-error-parse-error-unexpected-end-in-header-file/ Share on other sites More sharing options...
AndyB Posted June 24, 2006 Share Posted June 24, 2006 You actually have TWO unclosed 'loops' in that code. Quote Link to comment https://forums.phpfreaks.com/topic/12831-parse-error-parse-error-unexpected-end-in-header-file/#findComment-49198 Share on other sites More sharing options...
sixpack434 Posted June 26, 2006 Author Share Posted June 26, 2006 Hi, I know,The first if statement checks if the current page needs authentication, and the second if statement checks if the user is logged in. They are both closed in the footer file } }Why can't I do this in the header file. Someone please help Quote Link to comment https://forums.phpfreaks.com/topic/12831-parse-error-parse-error-unexpected-end-in-header-file/#findComment-49709 Share on other sites More sharing options...
major_domo Posted June 26, 2006 Share Posted June 26, 2006 I've not tried spreading { } across multiple documents. I keep them in the same file, so anyone reading my work can pick it up more easily, and bugs are simpler to track-down.If I have a dynamic header and footer file, but I'm not using a template class (usually don't, hate em all), I'll usually have a "mother" file specifying details for all of them. You might try something more like:[code]<?php // file name: motherfile.php, created by me when I made it.// specify which header & footerif ( foo ) { $headerFile = 'header01.inc'; $footerfile = 'footer01.inc';} else { $headerFile = 'header02.inc'; $footerfile = 'footer02.inc';}// specify which content$contentFile = 'about_us.inc';$title = 'About Us';// specify which contentinclude_once('doctype_html_strict.inc');?>[/code]Then in the document doctype_html_strict.inc:[code]<?php // file name: doctype_html_strict.inc, created by me after I made the other one. ?><DOCTYPE blah blah (real strict, I know)><html> <head><title><?=$title;?><title></head> <body><?php include_once( $headerFile ); ?><?php include_once( $contentFile ); ?><?php include_once( $footerfile ); ?> </body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12831-parse-error-parse-error-unexpected-end-in-header-file/#findComment-49730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.