Jump to content

[SOLVED] Showing a user if they're logged in or not


dgs

Recommended Posts

Alright, so, I have this PHP script installed for users to have accounts on my site.

 

There's this code that I put on a page to see if a person is logged in or not. If they aren't, it asks them to, but it also hides everything under that code.

 

I want to be able to put a code on one of my pages to show the user whether they are logged in or not without hiding the rest of the page.

 

How can I do that?

Oh, sorry, here:

 

<?php
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("<p>You are not logged in, <a href='/members/login.html'>click here</a> to login.</p>");
echo "<p>You are logged in as <strong>$username</strong></p>";
?>

Ah.  The problem is, you call the function die() which, well, kills any further loading beyond that point.  Give this a try:

<?php
if (!isset($_COOKIE['loggedin']))
{
echo "<p>You are not logged in, <a href='/members/login.html'>click here</a> to login.</p>";
}
else
{
echo "<p>You are logged in as <strong>$username</strong></p>";
}
?>

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.