Simple Machines Community Forum

Archived Boards and Threads... => Archived Boards => SMF Feedback and Discussion => Aiheen aloitti: FiskFisk33 - huhtikuu 01, 2008, 05:12:16 IP

Otsikko: Check if logged in
Kirjoitti: FiskFisk33 - huhtikuu 01, 2008, 05:12:16 IP
I want to make a file that checks if a user is logged in, and i have no idea how to do.
i need something like

<?php
(Some code here i guess)
If(user is logged in){
echo '1';
}
else{
echo '0';
}
?>

any ideas?
Otsikko: Re: Check if logged in
Kirjoitti: metallica48423 - huhtikuu 01, 2008, 05:23:02 IP

<?php
if($context['user']['is_logged'])
  echo 
'1';
else
  echo 
'2';
?>



Note if you only have one line of code after an if, you don't need the { }.  Any more and you do.

There are also a couple other common ones.

$context['user']['is_logged'] -- Set if member is logged in
$context['user']['is_guest'] -- Set if member is a guest
$context['user']['is_admin'] -- Set if member is an admin

and i think $context['user']['is_mod'] as well.

You can do print_r($context); to see all the variables and values for the $context array
Otsikko: Re: Check if logged in
Kirjoitti: FiskFisk33 - huhtikuu 01, 2008, 05:31:54 IP
How do i choose which user it checks then? replace the "user" with the username?
thanx btw x)

actually i tried that, and it didnt work, it was a file looking like this

<?php
global $context;

if ($context['fiskfisk33']['is_logged']){
echo "1";
}
else{
echo "0";
}
?>

and it was put in the root of the forum, but wouldnt work

what did i do wrong?
Otsikko: Re: Check if logged in
Kirjoitti: metallica48423 - huhtikuu 01, 2008, 06:23:00 IP
$context variables apply to the member which loaded the page. 'user' is constant, its not changing to meet the username or anything.

$context['user']['is_logged'] is a boolean value, meaning it is either zero/null/not set/false or 1/true.

what is it you are attempting to do?
Otsikko: Re: Check if logged in
Kirjoitti: FiskFisk33 - huhtikuu 01, 2008, 06:40:15 IP
I want to make a signature that shows wether i'm online on the forum or not, i thought that an easy way of doing it is a php file that outputs 1 or 0, but it has to be opened from a different server, so no, it will not be loaded by the user himself.

its actually for this signature :


(right now it only shows status stuff from xfire)


(and haha, metallica needs more cowbell? xD)
Otsikko: Re: Check if logged in
Kirjoitti: CmptrWz - huhtikuu 01, 2008, 06:43:32 IP
You could write your php to directly check the who's online information in the database, checking for your username.
Otsikko: Re: Check if logged in
Kirjoitti: FiskFisk33 - huhtikuu 01, 2008, 06:49:30 IP
Im sorry but i know nothing about smf, so i dont know how to do that..

..how?  :P
Otsikko: Re: Check if logged in
Kirjoitti: FiskFisk33 - huhtikuu 02, 2008, 04:20:21 AP
lulz, i cheated, i made it load the profile page (like this one http://www.simplemachines.org/community/index.php?action=profile;u=150844) and check for the word "Online"
This worked, but its not the best way :/
Otsikko: Re: Check if logged in
Kirjoitti: ccbtimewiz - huhtikuu 04, 2008, 06:04:44 IP
Lainaus käyttäjältä: FiskFisk33 - huhtikuu 01, 2008, 05:31:54 IP
How do i choose which user it checks then? replace the "user" with the username?
thanx btw x)

actually i tried that, and it didnt work, it was a file looking like this

<?php
global $context;

if ($context['fiskfisk33']['is_logged']){
echo "1";
}
else{
echo "0";
}
?>

and it was put in the root of the forum, but wouldnt work

what did i do wrong?

Try:

<?php global $context;
if (
$context['member']['id'] != '#') {
     echo 
'stuff'; } ?>