Gossamer Forum
Home : Products : Others : Gossamer Community :

Login/Logout Toggle on Static Pages

Quote Reply
Login/Logout Toggle on Static Pages
I have succesfully installed GCommunity. I was wondering, on my static pages, how do I insert code (JavaScript I assume) to toggle the login/logut depending on whether the user is logged in?

If someone is logged in, I want to show: "Logout"

If someone is logged out, I want to show "Login/Register"

THanks!
Quote Reply
Re: [Jobu] Login/Logout Toggle on Static Pages In reply to
Sweet! Didn't see the SSI option!

In user_ssi_login.html, I have:



Now I can call things properly from static pages using:

Code:
<!--#include virtual="/cgi-bin/community/community.cgi?do=ssi_login"-->


However, this doesn't appear to work from within my Links templates. I also tried using the same code as above that I have in user_ssi_login.html, but it always returns <li><a href="http://www.WiredBIZ.com/cgi-bin/community/community.cgi">User Login/Registration</a></li>, whether I am logged in or not.

In short, how do I insert code into my Links templates to check if I am logged in to community, and then print different HTML depending on if I am logged in or not?

Thanks!

Last edited by:

Jobu: Aug 18, 2006, 8:08 PM
Quote Reply
Re: [Jobu] Login/Logout Toggle on Static Pages In reply to
I did it!

Code:

<script language="JavaScript" type="text/javascript">
<!--

function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}


// Tests if the session id value is set and if the user is logged in
if (getCookie("Community_Name")) {
document.write("<li><a href='http://www.WiredBIZ.com/cgi-bin/community/community.cgi'>My Profile</a> | <a href='http://www.WiredBIZ.com/cgi-bin/community/community.cgi?do=user_logout'>Logout</a></li>");
} else {
document.write("<li><a href='http://www.WiredBIZ.com/cgi-bin/community/community.cgi'>User Login/Registration</a></li>");
}


-->
</script>
Quote Reply
Re: [Jobu] Login/Logout Toggle on Static Pages In reply to
If you didn't want to use javascript and you wanted to use SSI... this might be of help:

http://www.gossamer-threads.com/...i?post=271341#271341

- Jonathan
Quote Reply
Re: [jdgamble] Login/Logout Toggle on Static Pages In reply to
In Reply To:
If you didn't want to use javascript and you wanted to use SSI... this might be of help:

http://www.gossamer-threads.com/...i?post=271341#271341


Yeah, I saw that and that was really helpful as well. However, the SSI does not work from within non-lnks/community/forum PHP or CGI pages, so this was my solution for all pages.
Quote Reply
Re: [Jobu] Login/Logout Toggle on Static Pages In reply to
Well log.php can be called from ANY perl, php, or shtml file related or not related to links, so YES, it can work! It could also be easily translated to log.cgi if necessary. I personally just try and avoid as much javascript as possible to keep the possible errors to a minimum.

Tongue

- Jonathan