#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep 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") &#0124; &#0124; "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.
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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..."
  4. #3
  5. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    # 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;
    }
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>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 {
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    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..."
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    33
    Rep Power
    16
    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
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    pa, usa
    Posts
    8
    Rep 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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    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).]
  16. #9
  17. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>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".
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    Indeed.

IMN logo majestic logo threadwatch logo seochat tools logo