The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
why the **** doesn't this work??
Discuss why the **** doesn't this work?? in the Perl Programming forum on Dev Shed. why the **** doesn't this work?? Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 31st, 2000, 08:51 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: pa, usa
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
ugh, i've run into a problem... and i can't figure this crap out. i don't get an error, so i can't debug it, so maybe you experts out there can help me out.
this code below just keep's returning to the sub login, why?? why won't it go on! (i'm not stupid by putting the wrong pass and id in, so i'm stumped.)
code:
#!/usr/local/bin/perl
use CGI;
$field = new CGI;
require ("cgi-lib.pl");
&ReadParse(*form);
print "Content-type:text/htmlnn";
#script variables
$cl = "ryan";
$cp = "randels";
$scrurl = "http://www.fakeserver.com/cgi-bin/news.cgi";
$first = 0;
if ($first == 0) {
$first++;
&login;
} else {
if ($form{'guesslogin'} eq "ryan") {
if ($form{'guesspass'} eq "randels") {
if ($form{'action'} eq "addnews") {
&addnews;
} else {
&newINPUT;
}
} else {
print "pass is incorrect";
}
} else {
print "login is incorrect";
}
}
##script variables
sub login {
print <<END_OF_LOGIN;
<html>
<HEAD><TITLE>Spazznet News Updater</TITLE></HEAD>
<body bgcolor="#FFFFFF">
$first
<form method=post action="$scrurl">
Admin ID: <input type="text" name="guesslogin"><br>
Password: <input type="password" name="guesspass"><br>
<input type="Submit" name="Submit">
</form>
</body>
</html>
END_OF_LOGIN
}
sub newINPUT {
open (OLDNEWS, "news.txt") | | "Sorry! But we cannot open news.txt!";
$news = <OLDNEWS>;
close (OLDNEWS);
print <<END_OF_INPUT;
<html>
<HEAD><TITLE>Spazznet News Updater</TITLE></HEAD>
<body bgcolor="#FFFFFF">
<form method=post action="$scrurl">
News: <input type="text" name="newnews" value="$news"><br>
<input type="hidden" name="action" value="addnews">
<input type="Submit" name="Submit">
</form>
</body>
</html>
END_OF_INPUT
}
sub addnews {
open(NEWS, ">news.txt");
print NEWS $form{'newnews'};
close(NEWS);
}
------------------
rrandels.
|

July 31st, 2000, 10:38 PM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
rrandels,
i am just re-writing your script.Just i want show you how easily it can be done..
-----------
#!/usr/local/bin/perl
use CGI;
$q = new CGI;
print $q->header;
//print page header
#script variables
$cl = "ryan";
$cp = "randels";
$scrurl = "http://www.fakeserver.com/cgi-bin/news.cgi";
$guesslogin=$q->param('guesslogin');
$guesspass=$q->param('guesspass');
$action=$q->param('action');
//get the parameters from forms..
if($action=="login"){
if ($guesslogin eq "ryan") or ($guesspass eq "randels") {
print "login Failedn";
}else{
print "Successfully logged inn";
&newINPUT;
//New input screen..
}
}elsif ($action=="addnews"){
&addnews;
//Add News..
}
}else{
&login;
}
------
just improve your script logic..
Good luck!!
------------------
SR -
webshiju.com
"The fear of the LORD is the beginning of knowledge..."
|

July 31st, 2000, 10:49 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
# this two lines are redundant
$cl = "ryan";
$cp = "randels";
# since you explicitly declared..
if ($form{'guesslogin'} eq "ryan") {
if ($form{'guesspass'} eq "randels") {
Your sub newINPUT { needs to have
<input type="hidden" name="guesslogin" value="ryan">
<input type="hidden" name="guesspass" value="randels">
or else you will never get to "&addnews;" at all.
Anyhow, the logic of your code is too poor starting from the if ($first == 0) { line to ##script variables line.
>>this code below just keep's returning to the sub login
because the following is always true regardless what $first is.
if ($first == 0) {
$first++;
&login;
}
|

July 31st, 2000, 10:56 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>if ($guesslogin eq "ryan") or ($guesspass eq "randels") {
Shouldn't it be..
if ($guesslogin ne "ryan") or ($guesspass ne "randels") {
>>if($action=="login"){
Much better idea. So rrandels, you need to add
<input type="hidden" name="action" value="login"> to sub login {
|

July 31st, 2000, 11:04 PM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
if ($guesslogin ne "ryan") or ($guesspass ne "randels") {
freebsd,
yea,Actually i didn't see that..working last 24 hours with out any rest.....
>>if($action=="login"){
sub login {
print <<END_OF_LOGIN;
<html>
<HEAD><TITLE>Spazznet News Updater</TITLE></HEAD>
<body bgcolor="#FFFFFF">
$first
<form method=post action="$scrurl">
Admin ID: <input type="text" name="guesslogin"><br>
Password: <input type="password" name="guesspass"><br>
<input type="hidden" name="action" value="login">
<input type="Submit" name="Submit">
</form>
</body>
</html>
END_OF_LOGIN
}
sub newINPUT {
open (OLDNEWS, "news.txt") | | "Sorry! But we cannot open news.txt!";
$news = <OLDNEWS>;
close (OLDNEWS);
print <<END_OF_INPUT;
<html>
<HEAD><TITLE>Spazznet News Updater</TITLE></HEAD>
<body bgcolor="#FFFFFF">
<form method=post action="$scrurl">
News: <input type="text" name="newnews" value="$news"><br>
<input type="hidden" name="action" value="addnews">
<input type="Submit" name="Submit">
</form>
</body>
</html>
END_OF_INPUT
}
------------------
SR -
webshiju.com
"The fear of the LORD is the beginning of knowledge..."
|

August 1st, 2000, 04:21 AM
|
|
Contributing User
|
|
Join Date: Jul 1999
Posts: 33
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
are you guys sure this works?
if ($guesslogin ne "ryan") or ($guesspass ne "randels") { .......
I would have thought it would have been like: if (($guesslogin ne "ryan") or ($guesspass ne "randels")) {.....
Hmmm.
Also, rrandels, maye you should try writing your perl scripts with this in them:
#!/usr/local/bin/perl -w
Imo
|

August 1st, 2000, 07:45 AM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: pa, usa
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
alright, thanks alot guys, i'll try that out when i get home...
for the structure of my original code, i forgot to remove all the stupid things you do when you're trying to debug when you don't get an error, so that's the reason for the first varialbe and not using cl and cp instead of ryan & randels.
just to check, this is my new "handling code":
if($action=="login"){
if (($guesslogin ne "ryan") or ($guesspass ne "randels")) {
print "login Failedn";
}else{
print "Successfully logged inn";
&newINPUT
}
} elsif ($action=="addnews"){
&addnews
}
}else{
&login
}
now, just to get this straight, i am still gonna use all the sub's already in my original script, but i should use the param function to get the info from the login form?
------------------
rrandels.
|

August 1st, 2000, 09:41 AM
|
|
Contributing User
|
|
Join Date: Aug 2000
Location: Indiana
Posts: 614
  
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
|
|
No (at least IMO). The param method (which is part of CGI.pm) is very wossy and takes away from the fun of perl programing  . Just create a Data Parsing subroutine:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
sub parse_data {
####Post Data
read(STDIN, $namevalues, $ENV{'CONTENT_LENGTH'});
@namevalues = split(/&/, $namevalues);
foreach $namevalue (@namevalues) {
($name, $value) = split(/=/, $namevalue);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$POST{$name} = $value;
}
####Get Data
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
($name,$value)=split (/=/,$item,2);
$value=~tr/+/ /;
$value=~ s/%(..)/pack("c",hex($1))/ge;
$GET{$name}=$value;
}
}
[/code]
Anything posted using the POST method will be $POST{name} and GET method would be $GET{name}
[This message has been edited by JonLed (edited August 01, 2000).]
|

August 1st, 2000, 02:43 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
>>The param method (which is part of CGI.pm) is very wossy and takes away from the fun of perl programing
Just so you all know, if your site allows non-english characters form input from your visitors, never use CGI.pm and cgi-lib.pl. They will filter out multibytes encoding chars, especially with Chinese's Big5 which I often deal with. It's not too difficult to write your very own "Data Parsing subroutine".
|

August 2nd, 2000, 08:27 AM
|
|
Contributing User
|
|
Join Date: Aug 2000
Location: Indiana
Posts: 614
  
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
|
|
|
Indeed.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|