Jump to content

sixpack434

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sixpack434's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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
  2. 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 authentication if(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 116 Obviously 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
×
×
  • 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.