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! 

Link to comment
Share on other sites

<?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 {
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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