Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
|
11-19-2007, 07:57 AM
|
#16
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
This is the page i called register.pl
Quote:
#!/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>
<input type="text" size=20 value="" name="DOB"/><br />
<br />
<input type="submit" value="Send">
</form>
</body>
</html>
END
}
sub getWelcomeHTML
{
print <<END;
<html>
<head>
<title>Internet Application Programming</title>
</head>
<body bgcolor="lightyellow"><center><u>Login facility</center></u></body><br />
<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />
<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />
<input type="submit" value="Login">
</body>
</html>
END
}
sub getErrorHTML
{
print <<END;
<html>
<head>
<title>Internet Application Programming</title>
</head>
<body bgcolor="lightyellow"><center><u>LOGIN</center></u></body><br />
<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />
<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />
<input type="submit" value="Login">
</body>
</html>
END
}
|
and this is the page where it checks it which is called check.pl
Quote:
#!/usr/bin/perl
$length = $ENV {'CONTENT_LENGTH'};
read (STDIN,$data,$length);
($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);
print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";
$file = "cookie.txt";
if (open (OUTFILE,"> $file"))
{
print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
|
|
|
|
11-19-2007, 07:58 AM
|
#17
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
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
|
|
|
11-19-2007, 03:18 PM
|
#18
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
11-19-2007, 04:25 PM
|
#19
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
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
}
]
Code:
#!/usr/bin/perl
$length = $ENV {'CONTENT_LENGTH'};
read (STDIN,$data,$length);
($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);
print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";
$file = "default.db";
if (open (OUTFILE,"> $file"))
{
print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
Code:
#!/usr/bin/perl
use strict;
use warnings 'all';
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
#############################
my $header = "header.txt";
my $footer = "footer.txt";
my $pw = "demo";
############################
my $cookiename = "linkpop";
my $pass= param('pass');
my $tasty = cookie($cookiename);
my $edit = url_param("edit");
my $rem = url_param("rem");
use POSIX;
use DB_File;
my %default;
my $default = "default.db"; # location of database
###############################################################################################################
# COOKIE CHECKING
###############################################################################################################
# First check if we saved a cookie last time
if($tasty)
{
print header(-expires=>'now'),
start_html("Script name");
&processing;
print end_html;
exit;
}
########################################################################################################
# Password checking
########################################################################################################
unless ($pass eq $pw)
{
print header(-expires=>'now'), start_html("Login");
print <<"FORM";
<form action="" method="POST">
<table width="296" border="2" align="center" cellpadding="2" cellspacing="0" bordercolor="#0033FF">
<tr>
<td width="286"><table width="100%" height="100%" border="0" align="center" cellpadding="2">
<tr bgcolor="#0099FF">
<td colspan="2"><div align="center">User Login </div></td>
</tr>
<tr>
<td width="65">Username:</td>
<td width="196"><input name="user" type="username" id="user"></td>
</tr>
<tr>
<td width="65">Password:</td>
<td width="196"><input name="pass" type="password" id="pass"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div></td>
</tr>
</table><tr>
<a href="http://localhost/net/register.pl">click here to register</a>
</tr>
</form>
FORM
if (param())
{
if ($pass ne $pw)
{
print "<b>Mobin says wrong password asshole!</b>";
exit;
}
}
exit;
}
########################################################################################################
# Cookie setting
########################################################################################################
my $cookie = cookie(
-NAME=> $cookiename,
-VALUE=> $pass,
);
print header(-COOKIE => $cookie, -expires=>'now');
print start_html("");
|
|
|
11-19-2007, 08:56 PM
|
#20
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
11-20-2007, 04:34 AM
|
#21
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
no it wont
so
Code:
use POSIX;
use DB_File;
my %default;
my $default = "default.db
from that would it be as easy as saying ill change DB_FILE to test file and default.db to default.txt lets say
or wil i av to change everything???
|
|
|
11-20-2007, 07:21 AM
|
#22
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
11-20-2007, 01:23 PM
|
#23
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
aint got a clue what that meant mate sorry
|
|
|
11-20-2007, 02:27 PM
|
#24
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
11-20-2007, 04:06 PM
|
#25
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
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
Code:
#!/usr/bin/perl
$length = $ENV {'CONTENT_LENGTH'};
read (STDIN,$data,$length);
($fname, $lname, $username, $password, $dob ) = split(/&/,$data);
($firstkey, $fname) = split(/=/,$fname);
($firstkey, $sname) = split(/=/,$lname);
($firstkey, $Username) = split(/=/,$username);
($firstkey, $Password) = split(/=/,$password);
($firstkey, $DOB) = split(/=/,$dob);
print "Content-Type: ", "text/html\n\n";
print "First name: ", $fname, "\n";
print "Last name: ", $sname, "\n";
print "User name: ", $Username, "\n";
print "Password: ", $Password, "\n";
print "D.O.B: ", $DOB, "\n";
$file = "cookie.txt";
if (open (OUTFILE,"> $file"))
{
print OUTFILE "$fname - $sname - $Username - $Password - $DOB\n";
}
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>
<input type="text" size=20 value="" name="DOB"/><br />
<br />
<input type="submit" value="Send">
</form>
</body>
</html>
END
}
sub getWelcomeHTML
{
print <<END;
<html>
<head>
<title>Internet Application Programming</title>
</head>
<body bgcolor="lightyellow"><center><u>Login facility</center></u></body><br />
<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />
<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />
<input type="submit" value="Login">
</body>
</html>
END
}
sub getErrorHTML
{
print <<END;
<html>
<head>
<title>Internet Application Programming</title>
</head>
<body bgcolor="lightyellow"><center><u>LOGIN</center></u></body><br />
<form>
Enter Username<br>
<input type="text" size=20 value="" name="username"/><br />
</form><br />
<form>
Enter Password<br>
<input type="password" size=20 value="" name="password"/><br />
</form><br />
<input type="submit" value="Login">
</body>
</html>
END
}
|
|
|
11-20-2007, 06:34 PM
|
#26
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
Code:
open( USERDB, "cookie.txt" );
my @userDb = <USERDB>;
close USERDB;
foreach my $userRecord ( @userDb ){
my ($fname,$sname,$Username,$Password,$DOB) = split / - /, $userRecord;
#
# validate user here....
#
}
Basic perl. No magic here.
--- rod.
|
|
|
11-20-2007, 07:27 PM
|
#27
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417
|
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.
|
|
|
11-21-2007, 05:36 PM
|
#28
|
Member
Registered: Oct 2007
Posts: 30
Original Poster
Rep:
|
Quote:
Originally Posted by theNbomr
Code:
open( USERDB, "cookie.txt" );
my @userDb = <USERDB>;
close USERDB;
foreach my $userRecord ( @userDb ){
my ($fname,$sname,$Username,$Password,$DOB) = split / - /, $userRecord;
#
# validate user here....
#
}
Basic perl. No magic here.
--- rod.
|
so rod will that code allow me to read of the txt file and log in??
can i ask what does??
|
|
|
11-21-2007, 06:58 PM
|
#29
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,417
|
|
|
|
All times are GMT -5. The time now is 05:25 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|