Determining if a member is logged in or not via SSI possible ?

Started by nosx, March 27, 2010, 01:36:45 AM

Previous topic - Next topic

nosx

Is it possible to determine if a member is logged in or not on a page outside of the forums via SSI and if so what is the code block that must be used.

TIA,
Nosx

Matthew K.

#1
I've not dealt with a lot of SSI.

So I'm not positive this will work for you, however it's worth a shot.

Assuming this is at the base of SMF.

<?php require("SSI.php"); ?>

<?php

global $context;
if (
$context['user']['is_logged'])

?>


Now, I'll step back and see if anyone corrects me :)
Labradoodle-360

nosx

this seems to work for normal users, admins on the other hand seem to get the opposite of what you would expect. I created a php page named test.php and put the following code inside of it.

Code (php) Select
<?php
require("forum/SSI.php"); 

if (
$context['user']['is_logged'])
   {
    echo (
'user is logged in');
   }
else
   {
    echo (
'user is not logged in');
   }

?>


What happens is even when an admin is logged in the text that is displayed is "user is not logged in"
so not sure if something needs to be added to check if the user is an administrator or not. The same may be true for moderators but I have not tested with a moderator account. Anyway thanks again for your time and help.

Nosx

Matthew K.

Hmm, try this:
if (!$context['user']['is_guest'])

Labradoodle-360

nosx

Using ['is_guest'] does not seem to work either, it will say that you are logged in no matter what. I logged out and cleared all my cookies and shut down my browser and restarted and it still said I was logged in. I also tried the following code but it kept saying that I was logged out even tho I wasn't so I am really stumped now.

Code (php) Select
<?php
require('forum/SSI.php'); 

if (
$context['user']['is_logged'] || $context['user']['is_admin'] || $context['user']['is_mod']) {
echo ('user is logged in');
} else {
echo ('user is not logged in');
}

?>


Nosx

Matthew K.

Actually, the statement is written incorrectly, but it should output the same.

Lets see if any SSI experts have advixe for you.
Labradoodle-360

nosx

Thanks for the reply again and I did try variations of the code block above and as you said the results did were the same. If anyone has any suggestions on how to get this to work I would be most grateful to hear them.

TIA,
Nosx

Kays

What does the following show:


echo ' Hello ', $context['user']['name'];


One thing to try is to go into the Admin CP> Server Settings > Feature Configuration and set the following:

Enable local storage of cookies - unchecked
Use database driven sessions - checked

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

nosx

Quote from: Kays on March 27, 2010, 10:21:43 PM
What does the following show:


echo ' Hello ', $context['user']['name'];


One thing to try is to go into the Admin CP> Server Settings > Feature Configuration and set the following:

Enable local storage of cookies - unchecked
Use database driven sessions - checked

The reply from the above code is: Hello Guest even tho I was logged in as the admin at the time the script was called.

I then ventured into the ACP and looked at the items you described and they were set as follows.

Enable local storage of cookies - unchecked
Use database driven sessions - checked

This is exactly how you said they should be so I have no idea what is causing the problem.

Some things that may help narrow down the problem are.
The forum in question was upgraded from 2.0 RC1.2 to 2.0 RC3 and is not a fresh install of RC3
The following mods are installed on our forums.

1.  PM Attachments  1.4      
2.    Arcade Skin 2.5 RC1 1.0.0    
3.    Social Bookmarks 1.0    
4.    XFire + GSC Profile Modification 1.0    
5.    Ultimate Profile 0.9.1    
6.    Aeva Media 1.1b    
7.    SMF Articles 1.3    
8.    Stop Spammer 2.3.7    
9.    Annoy User 1.2    
10. Member Color Link 3.0.8
11. Footnotes    1.05
12. AjaxChat Integration 3.2.1 (modified for SMF 2 RC3)
13. Google Search Your Site 1.0.0    
14. Hide SMF Version 1.0.6    
15. Custom Form Mod 1.6    
16. eNinja - Admin Notes 0.9.2
17. Highslide Image Viewer 1.6
18. Team Page 3.5.4    
20. SMF Arcade 2.5 RC1

Again I would like to thank everyone for their time and replies in advance.
Nosx.

Kays

Is there anything on that page which could be destroying the session.

What doe this show?


echo '<pre>', print_r($_SESSION), '</pre>';



If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

nosx

Quote from: Kays on March 27, 2010, 11:26:20 PM
Is there anything on that page which could be destroying the session.

What doe this show?


echo '<pre>', print_r($_SESSION), '</pre>';


This is the output from the above call.

Array
(
    [session_value] => 2ebdc9ed96c34e37d6e938e1b3d04241
    [session_var] => fe3dbd2c40c0
    [robot_check] => 1269750188
    [mc] => Array
        (
            [time] => 1269741440
            [id] => 0
            [gq] => 0=1
            [bq] => 0=1
            [ap] => Array
                (
                )

            [mb] => Array
                (
                )

            [mq] => 0=1
        )

    [USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
    [old_url] => http://www.1upclan.info/forum/index.php
)
1


Although I must admit I am not entirely sure what the results mean.

Kays

Me neither really. :) But that does look like a valid SMF session.

Where is this page located in relation to your forums?

Could you post the code for that page?

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

nosx

Which page are you referring to? The page I am using to test the code or some other page. If you talking about the test page then the full contents of it are posted above.

Nosx

chilly

maybe try $user_info

$user_info['id']: 0 on guest else the userid
also it offers (var_dump test on my site):
  ["is_guest"]=>  &bool(false)
  ["is_admin"]=>  &bool(true)
  ["is_mod"]=>  &NULL

But im using $context too and it works just fine for me
if($context['user']['is_logged'])
{
ssi_logout();
}


Language Coordinator

nosx

Quote from: chilly on March 28, 2010, 05:05:01 PM
maybe try $user_info

$user_info['id']: 0 on guest else the userid
also it offers (var_dump test on my site):
  ["is_guest"]=>  &bool(false)
  ["is_admin"]=>  &bool(true)
  ["is_mod"]=>  &NULL

But im using $context too and it works just fine for me
if($context['user']['is_logged'])
{
ssi_logout();
}


Thanks for the reply, what exactly do I need to do with the code above ? Could you please show me an example. Much appreciated.

I tried the following but it did not seem to have any effect either (maybe I am using it incorrectly tho)

<?php
require('forum/SSI.php'); 

if (
$user_info['id'] == 0)
{
   
ssi_login();
}
else
{
   
ssi_logout();
}
?>



Nosx

Arantor

Daft question.

What is the URL to your forum and what is the URL to this page?

nosx

I think I discovered the problem. when I add the www part to my sites url the script works fine if I omit it then the script does not work. Anything I can setup so it works with or without the www part incase someone just enters the url w/o the www ?

Nosx

Arantor

That's what I was getting at.

Admin > Configuration > Server Settings > Subdomain independent cookies [tick]

Log out, log back in and it should work.

nosx

That did the trick thanks. Is there anything I should be aware of by enabling this setting (will it effect mods in anyway) or have a huge performance hit or anything else I should be aware of.

Thanks Again,
Nosx

Arantor

The only time it has any sort of issue is if you're using subdomains for services and it shouldn't be sending the cookie to subdomains, e.g. you have www1.site.com and www2.site.com and cookies for www1.site.com shouldn't go to www2.site.com while in SMF. Generally it's a non issue.

Advertisement: