CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Parse.cgi not working correctly

 



ubu
Deleted

Aug 19, 2000, 9:36 PM

Post #1 of 1 (595 views)
Parse.cgi not working correctly Can't Post

I have a program that will give away free space like Geocities will, a use signs up and my banners are shown on the pages. But if a user uploads a pic and then someone goes to that directly, there is no banner. I have this file to help add a banner to any file that doesn't already have one.

I can't seem to get this to work. If I go to the parse.cgi file, it will bring up a pop-up banner, but if I go to my members pages, html or pics it give me a 500 error. Does anyone see anything wrong with these two pieces of code that would cause all my file not to show up and give a error. I think it has to do with the .htaccess file in my members diretory. Everything work up to that point, and everything worked before I put it in my members directory.


Parse.cgi file:

#!/usr/bin/perl

# this is the url for your banner file for the popup
# this directory should be above or on a different domain then
# the directory you are parsing or you'll get a bad loop
# banner.html will also be called from this directory
$config{'BANNER_URL'} = 'http://www.yourdomain.com/banner';

# this is the path to your banner directory where banner.html
# which contains your banner code is located
$config{'BANNER_PATH'} = '/home/sites/path/to/banners';

# this is the path to the base of your web directory
# this probably will match the code in your htaccess/http.conf file
$config{'BASE_DIR'} = "/home/sites/path/to/base";

$|=1;

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

## GET FILE CALLED ###
if ($ENV{'REQUEST_URI'} =~ /\/$/) {
$ENV{'REQUEST_URI'} = $ENV{'REQUEST_URI'} . "index.html";
}

### GET AND STRIP PATH INFO ###
$ENV{'REQUEST_URI'} =~ s/\.(s*)html\/(.*)$/\.$1html/gi;
my $path_info = $2;

### GET AND STRIP QUERY INFO ###
$ENV{'REQUEST_URI'} =~ s/\?(.*)$//gi;
my $query_info = $2;

### SET BASE DIRECTORY PLUS FILE ###
my $base_dir = $config{'BASE_DIR'} . $ENV{'REQUEST_URI'};

#### OPEN FILE ####
undef $/;
open (DAT,"<$base_dir") &#0124; &#0124; print("nope $base_dir");
my $content = <DAT>;
close (DAT);

if ($content =~ m/<%PRINT_BANNER%>/i) {
unless($content =~ m/<!--<%PRINT_BANNER%>-->/i) {
open (BANNER,"$config{'BANNER_PATH'}/banner.html") &#0124; &#0124; print("nope $config{'BANNER_PATH'}/banner.html");
my $replace = <BANNER>;
close (BANNER);
$content =~ s/<%PRINT_BANNER%>/$replace/gi;
}
else { &popup; }
}
else { &popup; }

sub popup {
# generate random window name
srand(time);
my $window;
my @passset = ('a'..'z', 'A'..'Z', '1'..'9');
for (my $i = 0; $i < 10; $i++) {
my $randum_num = int(rand($#passset + 1));
$window .= @passset[$randum_num];
}

$content .= qq~

<script language='Javascript'>
function WinOpen(src)
{
OpenWin = window.open(src, '$window')
OpenWin.focus()
}
<!--
window.open('$config{'BANNER_URL'}/banner.html',
'$window',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=520,hei-ght=110');
// -->
</SCRIPT>
~;
}

$html .= $content;

print $html;


And here is the .htacess file that I use:

RewriteEngine on
RewriteRule \/(.*(\.htm|\.html|\.shtml|.{0}))$ /location_to/parse.cgi [T=application/x-httpd-cgi]

Any help would be appreciated.

Jamie


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives