CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced: Re: [webhay] return value from function: Edit Log

Administrator / Moderator

Jan 1, 2003, 10:31 AM

Views: 2898
Re: [webhay] return value from function

To answer your question....

sub gensid {  
my $sid = '';
my @alpha= qw/ q w e r t y u i o p l k j h g f d s
a m n b v c x z 6 7 8 9 0 5 4 3 2 1 / ;

$sid .= $alpha[ int rand @alpha ] for 1 .. 32;
return $sid;

my $sid = gensid();

But I recommend using either [url=]CGI::Session or one of options shown below instead of just using random characters to create session ids (I'm assuming you're creating session ids because of the $sid).

From CGI Programming with Perl:

use Digest::MD5; 

my $md5 = new Digest::MD5;
my $id = $md5->md5_base64( time, $$, $remote );
$id =~ tr|+/=|-_.|; # Make non-word characters URL-friendly

or what Apache::Session uses:

use MD5; 

sub generate_id {
return substr(MD5->hexhash(time(). {}. rand(). $$. 'blah'), 0, 16);


  • [url=]Re: Simple Session?
  • [url=](Ovid) Re: sessions: MD5 versus random strings

Please note that this question belonged in the Beginners forum -- it is not an Advanced question.

(This post was edited by Jasmine on Jan 1, 2003, 10:31 AM)

Edit Log:
Post edited by Jasmine (Administrator) on Jan 1, 2003, 10:31 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives