in reference to this...

Well I am going to post some code. I have a subroutine that will either return the users name or a message that will say the something to the fact "NOTLOGGEDIN" as I am assuming that no one will use that user name. If they do I will adjust.

If you could check out the code and see if there are some things that you would change. Do note that this does run... if you see something that will functionally not work agian please let me know.

#!d:\perl\bin\perl.exe -w use strict; use CGI; use CGI::Cookie; my $user = &get_userid; print "<p>whoa whoa whao $user"; sub get_userid{ print "Content-type:text/html\n\n"; ##################################################### #Here are global things that might need to be changed #these will be required from another file... had to #add for coding post though ##################################################### #Where are the Members directories? my $member_dir = "../../Members/"; #what is the name of the file that list the members my $member_file ="memberslist.cgi"; ##################################################### my $file; #the concat file, used in opens my $exact_file = "noneyet"; #this is the exact member file my @user_list; #this is the users info file holds #real cookie with user name my $login; #compares variable to id my $junk_file; #junk variable my $id; #here is the cookie id my $password; #this is the password from the cookie my %cookies; #hash to hold cookies my $nli = "NOTLOGGEDIN";#my not logged in value to return if(%cookies = fetch CGI::Cookie){ if($cookies{'UserName'}){ $id = $cookies{'UserName'}->value; }else{ return "$nli"; } if($cookies{'Password'}){ $password = $cookies{'Password'}->value; }else{ return "$nli"; } }else{ return "$nli"; } $file = "$member_dir/$member_file"; open (FH, "$file") or die "Could not open $file: $!"; while(<FH>){ chomp; ($login, $junk_file) = split(/\|\!\!\|/); if ($login eq $id){ $exact_file ="$junk_file"; } } close FH; if ($exact_file eq "noneyet"){ return "$nli"; } $file ="$member_dir/$exact_file.cgi"; open (FH, "$file") or die "Could not open $file"; while(<FH>){ chomp; push @user_list, $_; } close FH; if($user_list[0] eq $id){ if($user_list[1] eq $password){ return "$user_list[0]"; }else{ return "$nli"; } }else{ return "$nli"; } }
Basically the way that UBB works (exclusively describing for this example), is that once a user post, the users name and password are stored in cookies. I grab these. Then I check to see if this person is an actual user. If not I return NOTLOGGEDIN. UBB stores the users info in a file, I get this file name from memberslist.cgi by splitting then getting user names and file names. If they match I then open the one that coincides with the cookie $id. This file has the user name and the user password. I compare these, if they match I return the user name, else NOTLOGGEDIN.

It appears that this is very simple. I could expand to NOTAUSER, FAKEPASSWORD, but for my purpose now I don't need that functionality. Maybe the next version will have that.

I understand this code could hinder the speed of the program becuase it does not break when the user is found. I have tried break but get an use strict not allowed error. Could someone help speed this up for me?

while(<FH>){ chomp; ($login, $junk_file) = split(/\|\!\!\|/); if ($login eq $id){ $exact_file ="$junk_file"; } }
Those are the types of things I am looking for help with. Much thanks. :)

LeGo

LeGo


In reply to UBB find user id code by LeGo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.