Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: FlashSplash on May 09, 2010, 04:34:26 AM

Title: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 04:34:26 AM
Hi!.
I am user of SMF since february, so I don't know every functions yet. I was trying to do some login and logout function on my Home Page, which adress is (cartooncenter.pl) and forums adress is (cartooncenter.pl/forum). I have updated forum to version SMF 2.0 RC3, but it didn't work in RC2 either. Everything else (board news, whos online and these things are working properly). Login and Logout system is here (doesn't work really.) -cartooncenter.pl/index2.php
What am I doing wrong?

At the top of everything.
<?php
require_once('/home/cartoonc/public_html/forum/SSI.php');
$_SESSION['login_url'] = 'http://cartooncenter.pl' . $_SERVER['PHP_SELF'];
$_SESSION['logout_url'] = 'http://cartooncenter.pl' . $_SERVER['PHP_SELF'];
?>


And the login or logout button
            <?php
if ($context['user']['is_guest'])
{
echo
 
'<li><a href="login" class="signin"><span class="logowanie"></span></a></li>';
}
else
{
echo
 
'<li><span class="wyloguj">',ssi_logout();'</span></li>';
}
?>


And also sometimes (not all the time, but usually I am getting message:
QuoteNotice: SSI.php was unable to load a session! This may cause problems with logout and other functions - please make sure SSI.php is included before *anything* else in all your scripts! in /home/cartoonc/public_html/forum/SSI.php on line 172

SSI.php is always included before anything, in 1st line. :/

Regards,
FlashSplash
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 05:18:14 AM
Are you sure there's *nothing* before the <?php part? If the file is UTF-8 there may be invisible characters there that would prevent loading a session.
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 05:51:54 AM
How can I check if there are some ivisible characters? I am using Adobe Dreamweaver CS3.
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 05:53:03 AM
If you attach the file here, I can check it for you.

Note there are also some bugs in RC3 around this too, though they don't produce that error AFAIR.
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 06:31:05 AM
Attached. Thanks ;)
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 06:39:54 AM
Yup, this file was saved with what's known as a UTF-8 BOM (byte order mark), three bytes at the start of the file before <?php

Try this one. I just removed the three bytes with a binary editor (because that's the surest way of checking) but many editors including Notepad++ are capable of the conversion, and really Dreamweaver isn't the best for full on code editing, based on many similar comments here.
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 06:56:29 AM
I'm afraid it didn't help. Everything is still as it was:

- When I'm logging in it is not redirecting me to
$_SESSION['login_url'] = 'http://cartooncenter.pl' . $_SERVER['PHP_SELF'];
, but to forum. And also when I am logged in on Forum, I am not logged on main page. Why? Cookies? The same domain, everything should work.
I didn't change SSI.php file.
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 06:57:18 AM
So you're still getting 'could not load session' problems too?
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 07:11:23 AM
I'm afraid so, yes.
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 07:15:11 AM
What are the settings in Admin > Server Settings > Cookies and Sessions?
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 07:29:00 AM
(http://img146.imageshack.us/img146/81/cookies.png)

Cookie Name: SMFCookie863
Default login cookies length (in minutes): 360
Enable local storage of cookies: no
Use subdomain independent cookies: no
Force cookies to be secure: off (can't turn it on)
Use database driven sessions: yes
Allow browsers to go back to cached pages: yes
Seconds before an unused session timeout: 2880

EDIT:
Strange... It was working for a sec - it showed me the logout link (so I was logged in), and when I clicked on it, it didn't move me to forum. But, when I logged out, and I wanted to log in - it didn't work, It moved me to forum :/
EDIT2:

Maybe I will better explain my problem.
I can log in, and it works, but instead moving me to page I want, it redirects me to forum. When Im logged in, I still have option log in, instead of log out. Option log in is only when guest arrives, and option log out is only when user is logged in.
And also I get this strange message at the top of my site (sometimes it disapears, and then come backs after a while):
QuoteNotice: SSI.php was unable to load a session! This may cause problems with logout and other functions - please make sure SSI.php is included before *anything* else in all your scripts! in /home/cartoonc/public_html/forum/SSI.php on line 172
And again - sometimes the log out link appears, and everything is working, but when I try to log, it fails again.
Title: Re: SSI.php login-logout outside system problem.
Post by: Orstio on May 09, 2010, 10:30:38 AM
Are you also using DreamWeaver as the FTP client to upload the file?  If so there's a chance you undid the changes Arantor made.
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 10:37:45 AM
No, I use FileZilla Client.

Please - this is really important for me. If anybody have any idea just share it with us. I have to solve this puzzle :)
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 04:50:17 PM
I guess there is no solution, right? :D
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 04:54:50 PM
No, of course there's a solution, just that bumping after only 6 hours when we're all busy with other things just doesn't help you get it any quicker.

As I said, there are known issues with this functionality in RC3 anyway.

Try enabling subdomain independent cookies.
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 05:14:19 PM
Yeah, I know I am a son of a mother duck.

I am afraid id didn't work either.

Edit: Also I noticed, that the problem exists only when I am logged out - if I am logged in the message doesn't exist.
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 05:16:00 PM
/me glances at signature and sighs.

What happens now? Anything different?
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 05:17:41 PM
Oh, Im sorry.
No change at all.

On the second thought there is a change. Before I changed that, there was a problem when I was logged out and logged in. Now when I am logged in, everything works properly, but when I am logged out I can see this "Notice:" thing and when I am trying to log in it redirects me to forum instead of redirecting me to http://www.cartooncenter.pl/index2.php
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 05:19:32 PM
Did you try then emptying out your browser's cache and cookies?
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 05:29:01 PM
I celared the memory (cache and cookies), and it WAS working! I logged in, and it redirected me to page I wanted to be redirected (http://www.cartooncenter.pl/index2.php), and than I clicked logout and it also redirected me to page I wanted (http://www.cartooncenter.pl/index2.php)... but there was also again this damn notice. It only disapears when I delete this line (172) of code from SSI.php (at this moment I have unchanged version).

Okay I have a solution to my own problem!
This "Notice:" thing appears only when Im logged in, and click log out. So if I redirect it to some page without SSI.php (like some html page) there isn't going to be such a notice :D
But of course it is not real solution.

Also I noticed something ... strange.
If I have this:
<?php
require_once('/home/cartoonc/public_html/forum/SSI.php');
$_SESSION['login_url'] = 'http://www.cartooncenter.pl' . $_SERVER['PHP_SELF'];
$_SESSION['logout_url'] = 'http://southpark.cartooncenter.pl' . $_SERVER['PHP_SELF'];
?>

and Im logging in on page http://www.cartooncenter.pl/index2.php it takes me to http://www.cartooncenter.pl/index2.php - so when Im logging out from page http://www.cartooncenter.pl/index2.php it takes me to http://southpark.cartooncenter.pl/index2.php (which doesn't exists by the way).
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 05:53:19 PM
Thanks Arantor! I got a solution! Maybe not the best, but system works : )

I have just last question - how to put ssi_logout(); into <a href=""> in php?:
'<li><a href=""><span class="wyloguj"></span></a></li>';
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 05:58:18 PM
'<li><a href="' . $scripturl . '?action=logout;' . $context['session_var'] . '=' . $context['session_id'] . '"><span class="wyloguj"></span></a></li>';

Note that both $scripturl and $context must have been called with global first. (That's literally just what ssi_logout returns)
Title: Re: SSI.php login-logout outside system problem.
Post by: FlashSplash on May 09, 2010, 06:05:20 PM
Thanks for the link.

I have no idea why it failed again... It isn't working again, everything is the same as it was. It was so close, I didn't modified anything and suddenly it crashed.

Could you please tell me the name of this binary editior you are using?

Edit: Actually I just deleted this line 172 in SSI.php and everything is working.
// Make sure they didn't muss around with the settings... but only if it's not cli.
if (isset($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['is_cli']) && session_id() == '')
trigger_error($txt['ssi_session_broken'], E_USER_NOTICE);

What for was it created anyway? : )
Title: Re: SSI.php login-logout outside system problem.
Post by: Arantor on May 09, 2010, 08:04:53 PM
I used FrHed to edit the file.

What it's telling you is that it can't load the session properly, meaning nothing should work properly.

The three bytes added at the start are the UTF-8 Byte Order Mark, the explanation of which is far too convoluted to go into at this stage; look it up on Wikipedia.