Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

login issue... a new approach to the problem

Quote Reply
login issue... a new approach to the problem
As I continue my efforts to upgrade to linksSQL, I came across the same problem most users of links have seen...

(anyone interested in seeing my progress go to http://www.magicdirectory.com/linksSQL/)

BTW most of my problems have been solved because of Andy, many thanks.

I would like the login to display login / logout on all pages. Granted this problem has many fixes, but none practical for me. I use an include for in ssh of a php file for the html pages, and the cgi pages I cannot seem to get down. I can use <%if Username%> and it will work if I want to edit each individual cgi page. However, my header is where I want the login/logout to appear. Unfortuantely, the header appears in both html and cgi pages.

Here is what I have and what I would figure would work that I call in my header from <%log%>:

Code:

'log' => 'sub {
my $output;
if ($ENV{SCRIPT_NAME} =~ /nph-build/) {
$output = \'<!--#include virtual="/log.php" -->\';
}
else {
use CGI::Cookie;
my %cookie = fetch CGI::Cookie;
if ($cookie{"s"}) {
$output = qq| <a href="$CFG->{db_cgi_url}/user.cgi?logout=1">Logout</a>|;
}
else { $output = qq| <a href="$CFG->{db_cgi_url}/user.cgi">Login</a>|; }
}
return $output;

}',


The html pages load the php file and it will display logout / login correctly. The perl pages, however, always display logout. According to my reasoning this should work. Any thoughts once again is greatly appreciated.

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] login issue... a new approach to the problem In reply to
I figured out the problem, but I do not understand the cause...

If I create a php script wth this:

print_r($HTTP_COOKIE_VARS);

It will print all my cookies with this s variable when I am logged in
Code:
s = > 08fa6f06edcfa4d137dfab



If I create a perl script with this:

print $ENV{'HTTP_COOKIE'};

It will print all of my cookies EXCEPT the s variable...

Remember the s variable is created when you are logged in...


Why will php have record of this cookie but perl will not?



- Jonathan

Last edited by:

jdgamble: Aug 21, 2004, 2:51 PM
Quote Reply
Re: [jdgamble] login issue... a new approach to the problem In reply to
I figured it out...

Here is the code I am using that works...

Code:

'log' => 'sub {
my $output;
my $session_id = GT::CGI->cookie(\'s\') || GT::CGI->param(\'s\');
if ($ENV{SCRIPT_NAME} =~ /nph-build/) {
$output = \'<!--#include virtual="/log.php" -->\';
}
elsif ($ENV{QUERY_STRING} =~ /logout/) {
$output = "<a href=\'$CFG->{\'db_cgi_url\'}/user.cgi\'>Login</a>";
}
else {
if ($session_id) { $output = "<a href=\'$CFG->{\'db_cgi_url\'}/user.cgi?logout=1\'>Logout</a>"; }
else { $output = "<a href=\'$CFG->{\'db_cgi_url\'}/user.cgi\'>Login</a>"; }

}
return $output;

}',


I use <%log%> in my header template, and I use this as log.php...

Code:

<?
if (empty($HTTP_COOKIE_VARS["s"])) {
echo "<a href='http://www.magicdirectory.com/cgi-bin/linksSQL/user.cgi'>Login</a>";
} else {
echo "<a href='http://www.magicdirectory.com/cgi-bin/linksSQL/user.cgi?logout=1'>Logout</a>";
}
?>


Once again I hope this helps some people... let me know if it does...

- Jonathan
Quote Reply
Re: [jdgamble] login issue... a new approach to the problem In reply to
Due to some problems I have had with this (mainly the php file), I have a new solution. This version uses a perl file instead of a php file.

here is the perl file log.cgi

Code:

#!/usr/bin/perl
#================================
use strict;
use lib '/home/httpd/vhosts/magicdirectory.com/cgi-bin/admin';
use Links qw/$IN/;
Links::init('/home/httpd/vhosts/magicdirectory.com/cgi-bin/admin');
use Links::SiteHTML;
local $SIG{__DIE__} = \&Links::fatal;
main();
sub main {
#---------------------------------------------------
#
my $username = $IN->cookie('Community_Name') || $IN->param('Community_Name');
print $IN->header;
print Links::SiteHTML::display('include_login', {Username => $username});
}


If you use GCommunity, then make sure you have not renamed your session name under

Setup -> User Session -> session_cookie_name_user

If you do not use GCommunity, then "Community_Name" should be replaced with "s".

You should create a global, say, "login" with this sub routine:

Code:

sub {
my $output;

if ($ENV{SCRIPT_NAME} =~ /nph-build/) {
$output = '<!--#exec cgi="/cgi-bin/log.cgi" -->';
}
else {
$output = Links::SiteHTML::display('include_login');

}
return $output;

}


<%log%>, which you can put in your include_header.html file, will now automatically check to see what kind of file it is loaded. This requires SSI, so your files must be built with .shtml extension. Remember to also check your cgi paths.

Last but not least, you must create an "include_login" template file with something like this:

Code:

<%if Username%>
[<a href='<%db_cgi_url%>/user.cgi?logout=1'>Sign Out</a>,
<a href='<%db_cgi_url%>/user.cgi'>My Account</a>]
<%else%>
<a href="<%db_cgi_url%>/user.cgi">Sign In</a>
<%endif%>


Although javascript can seem easier, it is run from the user end. I am just completly anti-javascript when there is no need for it.

Hope someone uses this,

- Jonathan
Quote Reply
Re: [jdgamble] login issue... a new approach to the problem In reply to
Jonathan,

Very nice solution! Help me out immeasurably. Thanks so much for posting this.

Mike