webstudioro has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I have one problem with this script.
I insert the line &inc("login_admin.html");
for read my html document, but don't work. I want help, please.
Thank you.


This is my pl script:
#!perl use warnings; use CGI qw(:standard); use CGI::Cookie; use CGI; $query = CGI->new(); $user = "test"; $pws = "1234"; $nameCookie = "mm56"; $valueCookie = "012355"; $html_path = "c:/indigoperl/htdocs"; &inc("login_admin.html"); if ($query->param('logout') eq "yes") { &logout; } if ($query->param('login') eq "yes") { if ($query->param('user') eq ""){ print $query->header(-type=>'text/html'); print "<font color=\"red\">Enter your User name.</font>"; exit; } if ($query->param('pws') eq ""){ print $query->header(-type=>'text/html'); print "<font color=\"red\">Enter your password.</font>"; exit; } if (($query->param('user') eq "$user") && ($query->param('pws') eq "$p +ws")) { my %cookie = CGI::Cookie->fetch; my $cookie = CGI::Cookie->new(-name=>$nameCookie,-value=>$valueCookie, +-expires=>'+23h'); print header(-cookie=>$cookie); print "welcome\n"; exit; } print $query->header(-type=>'text/html'); print "Your User name / Password it's not good.<br>"; exit; } sub inc { %lvals = ( "!CGI_URL!","$cgi_url", ); local (%livals)=%lvals; local ($htfile)=@_; local ($htmlPath)="$html_path/$htfile"; open(TEMPLATE, "<$htmlPath") || die "Cannot open file: $htmlPath for r +ead! Error: $!\n"; $htmlPath=""; while(<TEMPLATE>) { $htmlPath .= $_; } close(TEMPLATE); for $ikey (keys(%livals)) { local($value)=$livals{"$ikey"}; $htmlPath =~ s/$ikey/$value/gm; } print "$htmlPath\n"; return; }
This is my HTML:
<html> <head> <title>Admin. Area</title> </head> <body><br><br><br><center><h3>Admin. Area</h3></center><br> <table align=center border=0> <form action="!CGI_URL!/test.pl?login=yes" method="post"> <tr><td align=center colspan=2> <b>Enter your user name and password</b></td></tr> <tr><td> User name: </td> <td> <input type=text name="user"></td></tR> <tr><td> Password: </td> <td> <input type=password name="pws"></td></tr> <tr><td colspan=2 align=center> <input type=submit value="Login to Admin. Area"> </td></tR> <tr><td align=center colspan=2> <hr> </td></tr> </form> </table> </body></html>

Replies are listed 'Best First'.
Re: Problem with my .pl script. Helpppp!
by PodMaster (Abbot) on Aug 31, 2003 at 11:05 UTC
    You should read the following tutorials Now consider this
    #!/usr/bin/perl use strict; use warnings; my $bob =1; my $rob =2; roy(); print "Content-Type: text/html\n\n"; print "HELLO ROB$rob\n\n"; exit 0; sub roy { print "\n\nHELLO BOB$bob\n\n"; return; } __END__ HELLO BOB1 Content-Type: text/html HELLO ROB2
    update: You would also benefit immensely from reading `perldoc perlstyle' and applying some of those suggestions (Perl::Tidy makes it easy).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Maybe there's rather a problem with the HTML form
      where you actually mix GET and POST methods:
      <form action="!CGI_URL!/test.pl?login=yes"
      Adding parameters to a URL after the question mark is the GET method, but
      method="post">
      is obviously the POST method.

      To be more concise, move the login parameter inside the form, thus removing any GET stuff. Like this:
      <form action="!CGI_URL!/test.pl" method="post"> [...] <input type=text name="user"> <input type=hidden name="login" value="yes">

        franktalisman++ good point. However, you *can* post to !CGI_URL!/test.pl?login=yes and still grab its value from $ENV{QUERY_STRING} *OR* you can uncomment line 458 of CGI.pm* which allows you to append query string data to the end of post data. However, by default what you said is mostly true if you are only concerned with CGI's param method.

        Hope this helps.

        * YMMV. It should be in the init sub. Just look for a comment that reads "APPEND to the POST data".

        antirice    
        The first rule of Perl club is - use Perl
        The
        ith rule of Perl club is - follow rule i - 1 for i > 1

        I try you example but don't work. The problem is with test.pl . The script don't read the html file.
      Ok. I know what it's the difference between my and local , but
      you don't tell me what it's the problem in my script.
        I may not use the words "your problem is" but I'm pretty sure I do point out an important one(study the code snippet, notice anything? when do the headers get printed? You do the same in your code, and webservers don't like it). CGI Help Guide covers everything there is to know about debugging programs in the CGI environment.

        At this point i'd like to refer you to About the PerlMonks FAQ -> How do I post a question effectively?. CGI Help Guide tell you how to get the detailed information How do I post a question effectively? tells you you're missing (ie, the detailed error messages).

        You should really go and read/tryout CGI Help Guide a couple of times now (once you read it it'll be easy for you to debug your program, and easier for others to help you).

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

        Try not using modules for a while. So that you can see the power of plain perl commands.

        If you can manage to do what you want without a module, you are going to understand better how much would you be saving by using the CGI.pm and HTML::Template.pm.

        This is what I do when I am having trouble with some code. I start cutting unnecesary things until I get it working. Sometimes, I write more but in a simpler way that I know it has to work...

        Afterwards, I can start adding things on a working script and know what parts have to be rewritten.