unexpected T_ELSE

Associate
Joined
18 Oct 2002
Posts
858
Location
Cheshire
Parse error: parse error, unexpected T_ELSE in /srv/www/htdocs/#######/includes/check-loggedin.php on line 13

PHP:
<?php
// this checks that if a user is trying to access a page where they should be logged in that they are actually logged in
// lets see if session is set, if not then they are using anonimous proxies, in which case we don't want them on the site
if (isset($_SESSION)) ($_SERVER['SCRIPT_NAME']) != "/login.php"; 
{
// ok, so, the sesion does exist now look to see if their email is set
if (!isset($_SESSION['USER_EMAIL']))
{ 
// ### need to check if they allready are at the login page... lol ###
// email is not set, theirfor they have not logged in so we bounce them to the login page
header("Location: login.php");
} 
} else
// The session is not set, their is something seriously wrong, so we bounce them to the login page anyways
{ header("Location: login.php");
} ?>

Perhaps it's coz it's after midnight and tomarrow I'll call myself stupid, but I can't find out why it causing an error.

Can anyone see it?

Thanks
 
Nope, he's actually screwed up the condition on the first first if statement, causing the interpreter to interpret the following braces as unbound, which is why an else statement thereafter is not allowed :) There are actually no syntax errors up until the else, despite the first conditional statement not actually making sense.

Don't know exactly how the script is supposed to work, but I'm assuming it should be something like this:
Code:
if (isset($_SESSION) && $_SERVER['SCRIPT_NAME'] != "/login.php"))
{
    // ...
}
else
{
    // ...
}

But, theirs too many close brackets in that top if statement.....

I tried using &&'s and it just threw it back at me....

the script get ran on every page... it's part of a web based application that i'm creating.
it basically says first it sees if their is a session open, which their should be coz immediatly befor this script it creates one....
Next, is the user email address set if it isn't then their not logged in and they need to go back to the login page....
However, if they are at the login page then they don't need to be sent to the login page....

Does that help?

Thanks
 
heh, I go from doing NONE at all to very verbose....

At least I can understand what the code is supposed to do... and read me own thaughts.... you should see the notes on the account management scripts.... PMSL
 
they're not as bad as some I've seen - whatever you need to do to keep track of the code. What I can't stand is:

Code:
# check to see if user isn't logged in
if ($_SESSION['islogged'] !== true) {
# send away
  header('Location: /login.php');
}
there's a guy here who does that and it does my brain in!

What does your brain in?
 
neh.... to no techies using comments make it so that they can distinguish what the code does and thus you quickly get elevated to godhood.....
 
Good catch :p



Right, if I've understood you correctly, it should be something like this:
Code:
<?php

if (isset($_SESSION))
{
    if (!isset($_SESSION['USER_EMAIL']) && $_SERVER['SCRIPT_NAME'] != '/login.php')
    { 
        header('Location: login.php');
    } 
}
else if ($_SERVER['SCRIPT_NAME'] != '/login.php')
{
    header('Location: login.php');
}

?>

Sorry I not been on a while... my brain exploded...

tried the above and I get....

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

* This problem can sometimes be caused by disabling or refusing to accept cookies.

Looks like we got an if thats wrong....
 
Back
Top Bottom