Jump to content

[SOLVED] PHP IF guest statment!


jamesxg1

Recommended Posts

if isset($_SESSION['groupid'])
{
// protected content...
}
else
{
echo "You must be logged in to view this page.";
}

 

A better way to do it would be a negative test at the beginning.  Test to see if the person is not logged in and echo, if it passes that test, then display content.

 

if (!isset($_SESSION['groupid'])) // if there is no "group id" set, then...
{
echo "You must be logged in to view this page.";
exit(); // This line is "What happens if not logged in",
         // so, you can use exit() or a redirect or whatever.
}
else
{
// Protected content
}

 

The second one lets you use it in an include at the top of the page a little easier if you're designing a large site.

if isset($_SESSION['groupid'])
{
// protected content...
}
else
{
echo "You must be logged in to view this page.";
}

 

A better way to do it would be a negative test at the beginning.  Test to see if the person is not logged in and echo, if it passes that test, then display content.

 

if (!isset($_SESSION['groupid'])) // if there is no "group id" set, then...
{
echo "You must be logged in to view this page.";
exit(); // This line is "What happens if not logged in",
         // so, you can use exit() or a redirect or whatever.
}
else
{
// Protected content
}

 

The second one lets you use it in an include at the top of the page a little easier if you're designing a large site.

 

Worked!,

 

Thanks mate

 

James.

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.