Advertisement:

Check if logged in

Aloittaja FiskFisk33, huhtikuu 01, 2008, 05:12:16 IP

« edellinen - seuraava »

FiskFisk33

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?

metallica48423


<?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
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

LainaaMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

FiskFisk33

#2
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?

metallica48423

$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?
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

LainaaMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

FiskFisk33

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)

CmptrWz

You could write your php to directly check the who's online information in the database, checking for your username.

FiskFisk33

Im sorry but i know nothing about smf, so i dont know how to do that..

..how?  :P

FiskFisk33

#7
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 :/

ccbtimewiz

#8
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'; } ?>

Advertisement: