Cgi -> Php

martinatkinson

Registered
Greetings!

I currently have a CGI script that I wrote for my site, I would like to port it to PHP since that is faster then CGI and I am not forced to put the script in my cgi-bin folder. Here is the script:

Code:
#!/usr/bin/perl

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

@values = split(/$/,$ENV{'QUERY_STRING'});

foreach $i (@values) {
($varname, $mydata)=split(/=/,$i);

open(INF,"../$mydata") or dienice();
@grok = <INF>;
close(INF);

open(IN,"navigation.temp") or dienice();
@htm = <IN>;
close(IN);
	
foreach $htm(@htm) {
	if($htm =~ /<!--CONTENT-->/){
		foreach $grok(@grok) {
			print "$grok";
		}
	}
	print "$htm";
}
				
sub dienice {
	print qq(<font size="-2" face="Arial">Sorry, an error occured while opening the database.  Please notify MyTownLink.com (<a href="mytownlink\@mytownlink.com">mytownlink\@mytownlink.com</a>) of this error: $!</font>);
	
	exit;
}
}

So, for example if you call www.mysite.com/index.cgi?data=path/to/file.html Then it would print out the template and include the file.html in the specific region.

Now, can anyone help me with porting this to PHP? I am just getting to learn and any help would be appreciated.

One thing that would need to be added to the script is that for some reason if the script calls a html document that is outside of its own directory all the links and images for that document will break. I need someway of locating all the links and dynamically reformatting them before being displayed.

Thanks in advance!

Albert
 
Back
Top