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?
<?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
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?
$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?
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)
You could write your php to directly check the who's online information in the database, checking for your username.
Im sorry but i know nothing about smf, so i dont know how to do that..
..how? :P
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 :/
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'; } ?>