translating memcache php code to perl

J

joe

Hello I was able to set up cookie authenticaion on my apache2 server
using php. Now I am trying to translate a couple of lines of code from
php to perl but I have not worked with cookies in perl so i am not
sure how to do this. Is there a better way to enable cookie / perl
authenticaion in apache2 or should I just keep hacking this code?

This are the lines of code


http://authmemcookie.sourceforge.net/


$memcache = new Memcache;
$memcache->connect('localhost', 11000) or die ("Could not
connect");
$key=md5(uniqid(rand(), true).$_SERVER["REMOTE_ADDR"].time());
$value="UserName=".$my_user."\r\n";
$value.="Groups=".$my_groups."\r\n";
$value.="RemoteIP=".$my_remoteip."\r\n";
$value.="Expiration=".$my_expiretime."\r\n";
if ($my_send_pass_flag!=FALSE) $value.="Password=".$my_password."\r
\n";
$value.="Email=".$my_mail."\r\n";
$value.="Name=".$my_nom."\r\n";
$value.="GivenName=".$my_prenom."\r\n";
$memcache->set($key,$value,false,$my_expiretime);
if ($my_expiretime!=0) setcookie($my_cookie_name,$key,time()+
$my_expiretime,$my_path,$my_domain,$my_secure);
else setcookie($my_cookie_name,$key,$my_expiretime,$my_path,
$my_domain,$my_secure);

header("Location: ".$my_referer);
exit;



I installed the memcached perl libraries and so far go this but not
sure how to link all the other pieces of code to my perl script

$memcache = new Cache::Memcached {
'servers' => "localhost:11000",
'debug' => 0,
'compress_threshold' => 10_000,
};
 
J

joe

Ok looks like i got it to work. I could be cleaner special on the
redirect part but for now it is ok.

$key = md5_hex($ENV{'REMOTE_ADDR'}.time());


my $mem = Cache::Memcached->new({

servers => ['localhost:11000'],

});

$value="UserName=".$my_user."\r\n";
$value.="Groups=".$my_groups."\r\n";
$value.="RemoteIP=".$my_remoteip."\r\n";
$value.="Expiration=".$my_expiretime."\r\n";
$value.="Password=".$my_password."\r\n";
$value.="Email=".$my_mail."\r\n";
$value.="Name=".$my_nom."\r\n";
$value.="GivenName=".$my_prenom."\r\n";


$mem->set("$key", "$value");

$cookie = $query->cookie(-name=>$my_cookie_name,
-value=>$key);

# -expires=>'+4h');

print $query->header(-cookie=>$cookie);
print $query->start_html('My cookie-set.cgi program');
print "<meta http-equiv=\"REFRESH\" content=\"0;url=$my_referer\">";
print $query->h3('The cookie has been set');
#print "key $key <BR>";
print $mem->get('$key');
print $query->end_html;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top