PDA

View Full Version : Need some help including file in cgi script


Colleen
01-25-2007, 04:37 AM
I am designing themes for people to use with the proxy script CGIProxy (http://www.jmarshall.com/tools/cgiproxy/).

I need to use includes so the end-user can easily edit their ads.

Using some code found here, I finally got my includes to work, however, I had to define the path to the file being included. I am hoping there's another way so people don't have to edit the path to their own.

Here's my code for this.
sub footer {
my($rightlink)= $NO_LINK_TO_START
? ''
: qq(<a href="$script_url"><i>Restart</i></a>) ;
print <<EOF ;
</div></div><div id="bottom"></div></div></div></div>
<div id="adblocka">
EOF
my $adblocka = '/home/proxydes/public_html/demos/bluesquareproxy/adblocka.html';
open (ADBLOCKA, "<$adblocka") or die "Can't open $adblocka: $!";
print <ADBLOCKA>;
close (ADBLOCKA);
print <<EOF ;
</div>
<div class="clear"></div></div>
<div id="adblockb">
EOF
my $adblockb = '/home/proxydes/public_html/demos/bluesquareproxy/adblockb.html';
open (ADBLOCKB, "<$adblockb") or die "Can't open $adblockb: $!";
print <ADBLOCKB>;
close (ADBLOCKB);
print <<EOF ;
</div>
<div class="clear"></div></div>
<div id="linkunit">
EOF
my $linkunit = '/home/proxydes/public_html/demos/bluesquareproxy/linkunit.html';
open (LINKUNIT, "<$linkunit") or die "Can't open $linkunit: $!";
print <LINKUNIT>;
close (LINKUNIT);
print <<EOF ;
</div>
</div>
</body>
</html>
EOF
}


I am new to this, so if that code is bad/unsafe, please let me know.

As you'll see I am including three files, any way to define the path to the files so my theme users won't have to edit the path? Perhaps a different way of including the file?

Thanks for your time. :)

Colleen
01-25-2007, 05:39 AM
I tested it without the path defined and it worked.

KevinADC
01-25-2007, 08:08 AM
Paths are always tricky. You can generally use the ENV hash (%ENV) for the common paths:

$ENV{DOCUMENT_ROOT}
$ENV{SCRIPT_FILENAME}
$ENV{SCRIPT_NAME}

just print them out in a perl script and the meaning should become obvious.