Jump to content

if else page to see if a user is logged on needs upgraded to php 5


jrtime

Recommended Posts

I had a simple php page, that I think was written in php 3 that would only display a page if a user had logged on:

 

 session_start();
$username = "bob";
if ($_SESSION['user'] != $username)
{?>
<?php
echo "You must logon.";
echo "<a href='login.php'>Logon<a/>;
?>
<?php
}
else}
?>
<html>
</html>
<?php
}
?>[code]

This worked fine till the server was updated to only accept php 5(Server information shows PHP Version: 5.2.12). Now, I am getting a parse error:

Parse error: syntax error, unexpected '}' , which is the } in the following section:

[code]<?php
}
else [code]

I ran the page through syntax checkers for php 5, and it it showing up as coded okay, but it is not working. Can anyone see what I am doing wrong or need to updated to make this work? Thanks! 

<?php 
session_start();
$username = "bob";
if ($_SESSION['user'] != $username)
{?>
<?php
echo "You must logon.";
echo "<a href='login.php'>Logon<a/>;
?>
<?php
}
else{ // You need to start { and not close } here
?>
<html>
</html>
<?php
}
?>

 

In

 

<?php
}
else}
?>

 

it should be

 

<?php
}
else {
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.