Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old July 31st, 2000, 08:51 PM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old July 31st, 2000, 10:38 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
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..."

Reply With Quote
  #3  
Old July 31st, 2000, 10:49 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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;
}

Reply With Quote
  #4  
Old July 31st, 2000, 10:56 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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 {

Reply With Quote
  #5  
Old July 31st, 2000, 11:04 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

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..."

Reply With Quote
  #6  
Old August 1st, 2000, 04:21 AM
Imo Imo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 33 Imo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
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

Reply With Quote
  #7  
Old August 1st, 2000, 07:45 AM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #8  
Old August 1st, 2000, 09:41 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
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).]

Reply With Quote
  #9  
Old August 1st, 2000, 02:43 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
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".

Reply With Quote
  #10  
Old August 2nd, 2000, 08:27 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 9
Indeed.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > why the **** doesn't this work??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway