Forum Moderators: coopster

Message Too Old, No Replies

unexpected T IF?

         

bysonary

7:13 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



hello again webmasterworld

I think I am doing this correctly but I can't be because I am getting errors.

I have written a login script which when the correct username and password are entered the

$_SESSION['Authenticated'] = true
is set to true like that.

now I have a page I want to be protected so I created a file called auth.php which consists of this...


<?php
session_start()
if($_SESSION['Authenticated']!= true)
{
header('Location: http://mydomain.co.uk/loginform.php');
}
else
{
exit;
}
?>


I am getting the error

Parse error: syntax error, unexpected T_IF in /home/www/juttuffi/auth.php on line 3

I have included the auth.php file at the top of the page i want to be protected, like this

include 'auth.php';

its at the very top of the page so the

[b]session_start();[/b]
will work and I really really cant see what the problem could be here so can anyone correct me where I am going wrong with this?

I would really appreciate any help or advice at all!

Nutter

7:28 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



You need a semicolon after session_start(), so it should be session_start();

bysonary

7:38 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



cheers mate

bysonary

7:46 pm on Jan 31, 2007 (gmt 0)

10+ Year Member



just a quick question relating to this script
[b]
<?php
session_start();
if($_SESSION['Authenticated']!= true)
{
header('Location: http://mydomain.co.uk/loginform.php');
}
else
{
exit;
}
?>
[/b]

<html>
<head><title>PROTECTED PAGE</title></head>
//HTML CODE BELOW
</html>

so the way i understand this, if its not true then it will redirect to the loginrequest page otherwise it will exit and continue to load the HTML code?

am i right?

eelixduppy

8:06 pm on Jan 31, 2007 (gmt 0)



Actually, it is incorrect, logically. To achieve what you are describing would only require the following:

session_start();
if($_SESSION['Authenticated']!= true)
{
header('Location: http://mydomain.co.uk/loginform.php');
exit(); //notice the placement of this
}