List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:June 13 2000 5:47pm
Subject:Question about cookies & creating file.pm
View as plain text  
Is there a good site for getting questions answered on using cookies and
creating file.pm?

I post this here only because of success from other postings - basically
everyone or most everyone knows their stuff and is very helpful.

Here it goes:

1st Part:
Cookies:
I am working on creating timeclock program for lab monitors with mysql
and would like to create
an admin login that uses cookies:  I am using the following in cgi.

use CGI::Cookie;
my $c = new CGI::Cookie(-name    =>  'UserID',
                          -value   =>  ['ADMIN'],
                          -expires =>  '+10m');

  print "Set-Cookie: $c\n";
  print "Content-Type: text/html\n\n";

Then I fetch the cookies with this:

%cookies = fetch CGI::Cookie;
$USERID = $cookies{'UserID'}->value;
if ($USERID ne "ADMIN") {
Then take user back to login screen etc.:
exit;
}

>ok, this works great with Netscape 4.7 on PC, but on IE or netscape for
Mac instead of getting sent back to the login screen I get a blank page
(unless you login).  So, to be nice I added this:
>This is near the beginning of the file.
if ($ENV{'HTTP_COOKIE'}) {

All the stuff in the middle etc......

>this is at the end of the file.
} else {
print "Couldn't find any cookies.  Perhaps you've got your browser";
print " set to refuse all cookies or you have not logged in?<p>Please";
print " check your settings.";
print "<br><br>";
print "<a href=\"http://$hostname/cgi-bin/timeclock/adminlogin.pl\">";
print "Please click here for the Admin Login Form</A>";
}

And that helps with the error of getting a blank screen and also helps
if browsers have cookies turned off.
Just curious why it works differently in different browsers.

2nd Part:
file.pm

I would like to learn how to add a way to call variables from a file:
because after 1 year of learning cgi-perl I
am very tired of retyping all the lines with new variables when
something changes.  For example,  I would
like to have a file that someone could edit for their machine or for
their passwords.
So, I would like $hostname="place host name here";,
$username="username", $password="password" etc. have all that in a file
called, for example,  file.pm  Then at the top of all the files I could
have use file.pm


Does anyone have an example of this or how it can be used?  Can this
work with CGI?  I keep plugging away.  I enjoy creating useful software
with mysql for educational uses - such as timeclocks, inventory
tracking, and starting to work on classroom scheduling program.  If
there is a place to share these types of programs please let me know, or
if these programs already exist, I'd like to take a look.

Thanks in advance,

Douglas
--

Douglas Brantz
Computer Consultant
Fine & Applied Arts
Appalachian State University
Boone, NC 28608

828-262-6312 FAX
828-262-6549 OFFICE
brantzdr@stripped


Thread
Question about cookies & creating file.pmDouglas Brantz13 Jun