Urgent! Perl/CGI script works on Linux, but not on NT

Sharky Forums


Results 1 to 8 of 8

Thread: Urgent! Perl/CGI script works on Linux, but not on NT

  1. #1
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post Urgent! Perl/CGI script works on Linux, but not on NT

    Hey folks, I got my script working fine on a Linux / Apache platform, but now the person I wrote this for can't seem to get the script working on an IIS 4.0 server. Their IIS server has a cgi-bin which runs some Perl stuff right now, which is why I'm a little baffled to say the least. So I guess my question to you is...is there any reason why this CGI script wouldn't work on an NT platform? I double checked all the functions I used and they're all NT compliant...sooooo I don't think it's my script.

    See the working script here: http://www.triggerland.com/cgi-bin/Perl/rand.cgi

    See the same script fail here: http://www.building2.net/cgi-bin/rand.cgi


    Here's the script:

    #!/usr/bin/perl
    #############################################
    # This script displays 3 distinctly different random images, which are read from a specified directory.
    # Author: Adam Sharp
    # E-mail: [email protected]
    # Date created: 01/02/2000
    #############################################

    ## Enter the URL if the image directory here: ##
    $url = "http://www.triggerland.com/testing/images/";

    ## Enter the relative directory of your images here: ##
    opendir(DIR,"../../public_html/testing/images/");

    ## No more changes are needed ##

    print "Content-type: text/html\n\n";

    print "<html><body><center>";

    @images = readdir(DIR);

    $number1 = int(rand(@images));
    $number2 = int(rand(@images));
    $number3 = int(rand(@images));


    until ( ( $number1 != 0 ) && ( $number1 != 1 ) )
    {
    $number1 = int(rand(@images));
    }

    print "<img src=$url$images[$number1]>";


    until ( ($number2 != $number1) && ( $number2 != 0 ) && ( $number2 != 1 ) )
    {
    $number2 = int(rand(@images));
    }
    print "<img src=$url$images[$number2]>";


    until ( ($number3 != $number2) && ($number3 != $number1) && ( $number3 != 0 ) && ($number3 != 1) )
    {
    $number3 = int(rand(@images));
    }
    print "<img src=$url$images[$number3]>";


    print "</center></body></html>";

    # END
    #############################################

    Thanks for any input guys. Is it a server setting that's wrong or something to that effect?

    [This message has been edited by Housen Maratouk (edited January 03, 2001).]

  2. #2
    Tiger Shark
    Join Date
    Sep 2000
    Posts
    525

    Post

    Well when you say same script, I assume you at least have the relevant paths set differently in the copy on the second server.... In other words: are you sure it's finding the image directory where you say it's supposed to be? Right at the start of the script, you have it opening the directory. If it cannot find it where specified, it will generate an error.

    This is just a quick guess based on having glanced at the script and the error the second link generated... so it may be something else.

    Housen

    P.S. Just as a word of advice, never use relative paths in scripts (or even static web docs, for that matters), as it makes them a bigger pain to manage than they need to be.

    ------------------
    Housen Maratouk
    Editor, Online Communities
    internet.com Corporation
    [email protected]

    [This message has been edited by Housen Maratouk (edited January 03, 2001).]

  3. #3
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    A good point. Doesn't the opendir function require a relative path? I tried plugging in the "$url" variable into that opendir function to no avail.

    And I *hope* the person that's trying to implement this CGI is setting is relative path correctly. I'm trying to help someone set it up on a webserver long distance here, and I'm baffled as to why he can't figure it out. He's not all that experienced with CGI stiff, so something must be wrong.

  4. #4
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    **Update**
    The script runs on my webserver which is on an NT platform, so I know it's not a platform issue now. Hmmmm, I still can't figure out what this guy is doing wrong with my script. Oh well, thanks anyways guys And thanks alot Housen for your input.

  5. #5
    Tiger Shark
    Join Date
    Sep 2000
    Posts
    525

    Post

    Originally posted by Grizzly:
    Doesn't the opendir function require a relative path?
    No, what most agree it should require is a path to root. So using the example of the path info you are pointing to, public_html/testing/images/, and assuming that public_html is a subdirectory that is located in the subdirectory named triggerland within the main directory named www in the root of the drive, you would have your opendir statement point to:

    /www/triggerland/public_html/images/

    Housen

    P.S. Oh, btw, I edited your post only to shorten the non-breaking strings of *'s, which were forcing the table to widen and making the discussion page look funny.

    ------------------
    Housen Maratouk
    Editor, Online Communities
    internet.com Corporation
    [email protected]

    [This message has been edited by Housen Maratouk (edited January 03, 2001).]

  6. #6
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Well the problem was resolved. Apparently the "opendir, and readdir" functions were causing all the whooplah on this particlar server. All I did was hardcode the image names into the @images array and it worked fine. I have no idea why this server won't take the opendir readdir functions right, but this is one of many problems with this webserver.

    This guy has been telling me that it's a "virtual server," which I have no idea what that means.

    This server also has no ability to allow .shtml files as the index file. According to this guy, it will only allow .htm and .html extensions on the index file, and there's not way we can add on .shtml as a possible extension on this "virtual server."

    Annoying to say the least. Anyways, thanks for you help Housen, and thanks foe editing my post so it stopped screwing up the table width on this discussion thread. My mistake Copying & pasting can do that sometimes.

    ------------------
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    P3-550e@733Mhz
    256MB PC-133 CL3 RAM
    Elsa Gladiac GeForce2 GTS
    40+ Gig's of combined HD
    CD-RW 8/4/32X
    DVD w/ Hollywood RealMagic DVD Decoder
    19" MAG DJ800 monitor
    Tornado 1000 case
    **Win2k Prof / Win2k Adv Server / Whistler Beta-1 Build 2296**
    ~~~~~~~~~~~~~~~~~~~~~~~~~

  7. #7
    Great White Shark Moridin's Avatar
    Join Date
    Sep 2000
    Posts
    5,351

    Post

    Originally posted by Grizzly:

    This guy has been telling me that it's a "virtual server," which I have no idea what that means.


    This means it is a second "logical" server operating on the same box.(or third, of forth, etc). This can be done in two ways, the first is that each site has a different IP address. The second is to check the host header to see which site the browser was trying to connect to.

    Eg. http://www.site_1.com and
    http://www.site_2.com

    would both be running from the same web server.




    ------------------
    Life is complex. It has real and imaginary parts.

  8. #8
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077

    Post

    Ah thanks for that input, makes sense now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •