login/registration facility for website in perl/cgi
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sub headers
{
$cookieval = shift @_;
# don't put any attributes, so will be session cookie with
# default values for domain and path
return "Set-Cookie: mode=$cookieval\nContent-Type: text/html\n\n";
}
basically ive got it reading what on the registration page and putting it in a txt file... but i need it to read of the txt page in the login page so itl allow the user to log in.. hope it makes sense
Your form(s) have a couple of problems. You probably want only only one form, with multiple input widgets, instead of each widget in its own form. Secondly, the form should have an action attribute that points to your CGI.
See http://www.w3.org/TR/html4/interact/forms.html for information on this. Normally, each form you create should specify a CGI which responds to submittal of the form.
If you want people to help you, please help them by posting source code using [C O D E] tags to preserve formatting.
--- rod.
ok what ive done now is ive created 3 files..
1 is register.pl this actually deals with the registration of the user. after the user registers hel click submit button and with the check.pl file it will store the details into a file called default.db (already done)
loginfinal.pl with this will read off the default.db file where the details are stored and log the user in if he has entered the login details correctly this part i need help with reading of the db file..
and the other is check.pl which stores the details onto the default.db file
this is the register.pl file
Code:
#!/usr/bin/perl
$cookiedata = $ENV{'HTTP_COOKIE'};
@cookies = split(/;/,$cookiedata);
foreach $c (@cookies)
{
($cname,$cvalue) = split(/=/,$c);
if ($cname eq 'mode')
{
$mode = $cvalue;
}
}
if ($mode eq "yes")
{
print headers("no");
print getWelcomeHTML();
}
elsif ($mode eq "no")
{
print headers("yes");
print getNotWelcomeHTML();
}
else
{
print headers("yes");
print getErrorHTML();
}
sub headers
{
$cookieval = shift @_;
# don't put any attributes, so will be session cookie with
# default values for domain and path
return "Set-Cookie: mode=$cookieval\nContent-Type: text/html\n\n";
}
sub getNotWelcomeHTML
{
print <<END;
<html>
<head>
<title>Internet Application Programming</title>
</head>
<body bgcolor="lightyellow"><center><u>Registration facility</center></u></body><br />
<form action="check.pl" method="post">
Enter Name<br>
<input type="text" size=20 value="" name="fname"/><br />
<br />
Enter Surname<br>
<input type="text" size=20 value="" name="sname"/><br />
<br />
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
<br />
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
<br />
Date Of Birth<br>
"Please enter D.O.B in the following format ddmmyyyy"<br />
<input type="text" size=20 value="" name="DOB"/><br />
<br />
<input type="submit" value="Send" "login.pl">
</form>
If you are already registerd please click on the following link to log in!!!!!
<a href="http://localhost/net/loginfinal.pl">click here</a>
</body>
</html>
END
}
Will this ever be a really large (membership greater then, say 100,000) site? If not, I suggest simply using a text flatfile database. Easier, faster.
--- rod.
Just read and write files. Use some simple locking mechanism (retrofit this once you have basic read/write access working).
Or study the docs on DB_file, and just figure out how to use it. Do that offline for easier testing.
--- rod.
You are storing a 'database' that evidently consists of one table. Since the only thing that a database manager contributes to this scenario is overhead and potentially file &/or record locking, why not store your data in a simple text file? When a user registers, add a record to the file. When a registered user logs in, lookup the password and other info from the file. You can easily read and parse a file of a few thousand records without significant delay on each login or registration.
--- rod.
ok ive reverted back to my 1st 1. where it actually stores the data in a txt file.. now ive got the login page all done but i just need to read of that text file when i click submit on the login page...
how do i make it read of the txt file..
many thanks for u help
If you used CGI.pm, you wouldn't have to code all that HTML, the fns/methods do that for you (and safer).
also, why do you have the '$firstkey' attached to every field? If it's all one rec, just put it at the first field pt.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.