Author Topic: [SOLVED] Showing a user if they're logged in or not  (Read 295 times)

0 Members and 1 Guest are viewing this topic.

Offline dgsTopic starter

  • Irregular
  • Posts: 10
  • Gender: Male
  • (Insert Personal Text Here)
    • View Profile
    • Deadly Gaming Studios
[SOLVED] Showing a user if they're logged in or not
« on: June 25, 2009, 10:59:52 PM »
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?

Offline magicdanw

  • Irregular
  • Posts: 8
    • View Profile
Re: Showing a user if they're logged in or not
« Reply #1 on: June 25, 2009, 11:26:24 PM »
Post the code so we can let you know why it's not working...

Offline dgsTopic starter

  • Irregular
  • Posts: 10
  • Gender: Male
  • (Insert Personal Text Here)
    • View Profile
    • Deadly Gaming Studios
Re: Showing a user if they're logged in or not
« Reply #2 on: June 25, 2009, 11:30:45 PM »
Oh, sorry, here:

Code: [Select]
<?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>";
?>


Offline magicdanw

  • Irregular
  • Posts: 8
    • View Profile
Re: Showing a user if they're logged in or not
« Reply #3 on: June 26, 2009, 12:11:44 AM »
Ah.  The problem is, you call the function die() which, well, kills any further loading beyond that point.  Give this a try:
Code: [Select]
<?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>";
}
?>

Offline dgsTopic starter

  • Irregular
  • Posts: 10
  • Gender: Male
  • (Insert Personal Text Here)
    • View Profile
    • Deadly Gaming Studios
Re: Showing a user if they're logged in or not
« Reply #4 on: June 26, 2009, 12:27:47 AM »
Ohhh, I get it.
I'm new to PHP, so I won't understand any of that :P

But thanks, I'll give it a try and tell you how it works out.

EDIT:: That did it! Thanks a bunch.  ;D
« Last Edit: June 26, 2009, 12:33:30 AM by dgs »