perl in CGI

Discussion in 'Perl Misc' started by Greg, May 6, 2005.

  1. Greg

    Greg Guest

    I write a very simple CGI using perl,here is the html

    <HTML>
    <HEAD>
    <TITLE>Welcome Page</TITLE>
    </HEAD>
    <BODY>
    Welcome to this web page. Currently, out my window I see:
    <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    </BODY>
    <HTML>

    Following is the sunmoon.cgi
    #!/usr/bin/perl -w
    use CGI qw:)all);
    my $hour=(localtime)[2];
    my $image;

    if($hour<6 or $hour >18){
    $image="night.jpg";
    }else{
    $image="day.jpg";
    }
    print header;
    print qq{<IMG SRC="$image" ALT="$image">\n};

    The two image files are there, but it can not be shown on the webpage,
    the webpage only shows:

    Welcome to this web page. Currently, out my window I see:

    What the problem? it seems the cgi was not executed. Thanks!
    Greg, May 6, 2005
    #1
    1. Advertising

  2. "Greg" <> wrote in news:1115402647.268743.189790
    @o13g2000cwo.googlegroups.com:

    > I write a very simple CGI using perl,here is the html
    >
    > <HTML>
    > <HEAD>
    > <TITLE>Welcome Page</TITLE>
    > </HEAD>
    > <BODY>
    > Welcome to this web page. Currently, out my window I see:
    > <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    > </BODY>
    > <HTML>


    I don't know anything about SSI, but that is SSI. Also, cig-bin is
    misspelled. So the issue is related to the configuration of SSI for your
    server, and not Perl.

    Sinan
    A. Sinan Unur, May 6, 2005
    #2
    1. Advertising

  3. Greg wrote:

    > I write a very simple CGI using perl,here is the html
    >
    > <HTML>
    > <HEAD>
    > <TITLE>Welcome Page</TITLE>
    > </HEAD>
    > <BODY>
    > Welcome to this web page. Currently, out my window I see:
    > <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    > </BODY>
    > <HTML>
    >
    > Following is the sunmoon.cgi
    > #!/usr/bin/perl -w


    use warnings; # is better than -w
    use strict;

    > use CGI qw:)all);
    > my $hour=(localtime)[2];
    > my $image;
    >
    > if($hour<6 or $hour >18){
    > $image="night.jpg";
    > }else{
    > $image="day.jpg";
    > }
    > print header;
    > print qq{<IMG SRC="$image" ALT="$image">\n};
    >
    > The two image files are there, but it can not be shown on the webpage,
    > the webpage only shows:
    >
    > Welcome to this web page. Currently, out my window I see:
    >
    > What the problem? it seems the cgi was not executed. Thanks!


    First: check the CGI script. What does it do when you run it from
    the command line?

    Second: check your image and HTML. Replace the CGI call with
    a static <img> tag to one of the images. Do you see the image now?

    Third: check your server logs; if your CGI script failed, your
    error messages will be here. Alternatively you can
    "use CGI:Carp qw(fatalsToBrowser);" and get your error messages
    served up on the webpage.

    Fourth: Don't capitalize your tags; it's bad form (and under strict
    XHTML syntax, wrong, although it's not what's causing your problem).
    --
    Christopher Mattern

    "Which one you figure tracked us?"
    "The ugly one, sir."
    "...Could you be more specific?"
    Chris Mattern, May 6, 2005
    #3
  4. Greg

    Greg Guest

    I check all the things, it still doesn't work. It seems the cgi has
    never been called. How can I check if the cgi being called?
    Thanks!

    Chris Mattern wrote:
    > Greg wrote:
    >
    > > I write a very simple CGI using perl,here is the html
    > >
    > > <HTML>
    > > <HEAD>
    > > <TITLE>Welcome Page</TITLE>
    > > </HEAD>
    > > <BODY>
    > > Welcome to this web page. Currently, out my window I see:
    > > <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    > > </BODY>
    > > <HTML>
    > >
    > > Following is the sunmoon.cgi
    > > #!/usr/bin/perl -w

    >
    > use warnings; # is better than -w
    > use strict;
    >
    > > use CGI qw:)all);
    > > my $hour=(localtime)[2];
    > > my $image;
    > >
    > > if($hour<6 or $hour >18){
    > > $image="night.jpg";
    > > }else{
    > > $image="day.jpg";
    > > }
    > > print header;
    > > print qq{<IMG SRC="$image" ALT="$image">\n};
    > >
    > > The two image files are there, but it can not be shown on the

    webpage,
    > > the webpage only shows:
    > >
    > > Welcome to this web page. Currently, out my window I see:
    > >
    > > What the problem? it seems the cgi was not executed. Thanks!

    >
    > First: check the CGI script. What does it do when you run it from
    > the command line?
    >
    > Second: check your image and HTML. Replace the CGI call with
    > a static <img> tag to one of the images. Do you see the image now?
    >
    > Third: check your server logs; if your CGI script failed, your
    > error messages will be here. Alternatively you can
    > "use CGI:Carp qw(fatalsToBrowser);" and get your error messages
    > served up on the webpage.
    >
    > Fourth: Don't capitalize your tags; it's bad form (and under strict
    > XHTML syntax, wrong, although it's not what's causing your problem).
    > --
    > Christopher Mattern
    >
    > "Which one you figure tracked us?"
    > "The ugly one, sir."
    > "...Could you be more specific?"
    Greg, May 6, 2005
    #4
  5. Greg

    Greg Guest

    I check all the things, it still doesn't work. It seems the cgi has
    never been called. How can I check if the cgi being called?
    Thanks!

    Chris Mattern wrote:
    > Greg wrote:
    >
    > > I write a very simple CGI using perl,here is the html
    > >
    > > <HTML>
    > > <HEAD>
    > > <TITLE>Welcome Page</TITLE>
    > > </HEAD>
    > > <BODY>
    > > Welcome to this web page. Currently, out my window I see:
    > > <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    > > </BODY>
    > > <HTML>
    > >
    > > Following is the sunmoon.cgi
    > > #!/usr/bin/perl -w

    >
    > use warnings; # is better than -w
    > use strict;
    >
    > > use CGI qw:)all);
    > > my $hour=(localtime)[2];
    > > my $image;
    > >
    > > if($hour<6 or $hour >18){
    > > $image="night.jpg";
    > > }else{
    > > $image="day.jpg";
    > > }
    > > print header;
    > > print qq{<IMG SRC="$image" ALT="$image">\n};
    > >
    > > The two image files are there, but it can not be shown on the

    webpage,
    > > the webpage only shows:
    > >
    > > Welcome to this web page. Currently, out my window I see:
    > >
    > > What the problem? it seems the cgi was not executed. Thanks!

    >
    > First: check the CGI script. What does it do when you run it from
    > the command line?
    >
    > Second: check your image and HTML. Replace the CGI call with
    > a static <img> tag to one of the images. Do you see the image now?
    >
    > Third: check your server logs; if your CGI script failed, your
    > error messages will be here. Alternatively you can
    > "use CGI:Carp qw(fatalsToBrowser);" and get your error messages
    > served up on the webpage.
    >
    > Fourth: Don't capitalize your tags; it's bad form (and under strict
    > XHTML syntax, wrong, although it's not what's causing your problem).
    > --
    > Christopher Mattern
    >
    > "Which one you figure tracked us?"
    > "The ugly one, sir."
    > "...Could you be more specific?"
    Greg, May 6, 2005
    #5
  6. Greg

    Tintin Guest

    "Greg" <> wrote in message
    news:...
    >I write a very simple CGI using perl,here is the html


    Actually, it's a SSI.

    >
    > <HTML>
    > <HEAD>
    > <TITLE>Welcome Page</TITLE>
    > </HEAD>
    > <BODY>
    > Welcome to this web page. Currently, out my window I see:
    > <!--#exec cgi="/cig-bin/sunmoon.cgi"-->
    > </BODY>
    > <HTML>
    >
    > Following is the sunmoon.cgi
    > #!/usr/bin/perl -w
    > use CGI qw:)all);
    > my $hour=(localtime)[2];
    > my $image;
    >
    > if($hour<6 or $hour >18){
    > $image="night.jpg";
    > }else{
    > $image="day.jpg";
    > }
    > print header;
    > print qq{<IMG SRC="$image" ALT="$image">\n};
    >
    > The two image files are there,


    Where do you think "there" is? I would be very surprised if you put the
    images in your cig-bin (sic) directory. And even if they were, they
    wouldn't be viewable unless you had a badly configured webserver.

    > but it can not be shown on the webpage,
    > the webpage only shows:
    >
    > Welcome to this web page. Currently, out my window I see:
    >
    > What the problem? it seems the cgi was not executed. Thanks!


    Then you have a SSI/webserver configuration issue. None of which is related
    to Perl.
    Tintin, May 7, 2005
    #6
  7. Greg

    Guest

    Greg <> wrote:
    > I check all the things, it still doesn't work. It seems the cgi has
    > never been called. How can I check if the cgi being called?


    If the SSI is implemented and fails to call the script, the displayed
    webpage will normally say that an error processing a directive has
    occured.

    Have a look at the source of the web page returned where it should
    be apparent. If the SSI directive appears there intact as a comment,
    it has not been run. Otherwise the results of the script may not
    have been what you expected although I see nothing wrong with the
    script.

    However as others have noted, this is a webserver configuration
    issue, not a Perl one.

    Axel
    , May 8, 2005
    #7
  8. Gunnar Hjalmarsson, May 8, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,207
    Jürgen Exner
    Jul 31, 2003
  2. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    492
    Michael Sparks
    Jul 30, 2005
  3. excord80
    Replies:
    17
    Views:
    608
    J Kenneth King
    Jan 29, 2009
  4. shumsta
    Replies:
    1
    Views:
    241
    Fabian Pilkowski
    Jul 22, 2005
  5. kath
    Replies:
    4
    Views:
    522
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page