From SHTML to PHP - converting the CGI include?
Moderator: General Moderators
From SHTML to PHP - converting the CGI include?
Hello.
I just converted the main page on my site from SHTML to PHP so that news posts are dynamically added.
My only problem is that the cgi counter that I had (which didn't work in html, hence SHTML) which uses this line:
<!--#include virtual="cgi-bin/counter.cgi" -->
...no longer works. Any help on this would be greatly appreciated. I'd also consider a new counter, if that was an effective solution.
Thanks.
I just converted the main page on my site from SHTML to PHP so that news posts are dynamically added.
My only problem is that the cgi counter that I had (which didn't work in html, hence SHTML) which uses this line:
<!--#include virtual="cgi-bin/counter.cgi" -->
...no longer works. Any help on this would be greatly appreciated. I'd also consider a new counter, if that was an effective solution.
Thanks.
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
the include() http://www.php.net/include function should be able to help you out. however i can't remember if it will execute you cgi script. read the documentation to be sure.
That seems to have worked, in that the script apparently runs, however I now get this large message as opposed to the count:
#!/usr/bin/perl ###################################### # the perl line might need changing # # In order to find out where your # # server has perl, type: # # which perl # # at a telnet session to your server # # # # # ###################################### #------------------------------------------------------------ # # Version 2.0 # # This script is copyright 1999 Brian Taber # # Distribution of this script is unlimited # please visit http://www.tgd-computers.com/bst # to obtain this script. # # Please do not modify this script in any way. # If you have any suggestions or questions # for me on the script, please e-mail btaber@hotmail.com # # # # Remember to upload the script in ASCII format! # The permissions for the script must be set before use!! # Here is the command lines in UNIX # # chmod 755 counter.pl # chmod 666 counter.txt # chmod 666 counterip.txt # # # #------------------------------------------------------------ # Modify the 5 varibles below to suit your needs. # CAUTION! Do not remove the semi-colins ; # Or Quotes '' # 1 - This is the directory where the digits are kept, this must be the full path to the images: $url = 'URL' ; # 2 - This is the extension on the digits: $ext = 'gif' ; # 3 - This is the text file that contains the count: $file = 'counter.txt' ; # 4 - This is the text file that contains the IP addresses of the visitors: $ip = 'counterip.txt' ; # 5 - This tells the counter to use images or text numbers. The deafult is use text. # read the ReadMe text file on how to use each of them. the selections are: # 1 - Use SSI and display text # 2 - Use SSI and display images # 3 - Use regular IMG tag to display image $type = 1 ; # # # DO NOT MODIFY BELOW THIS LINE!!! #------------------------------------------------------------------------------- # $addr = "$ENV{'REMOTE_ADDR'}"; $query = $ENV{'QUERY_STRING'} -1; $t = 0; open(COUNT, $file); $count = ; close(COUNT); @nums = split(//, $count); if ($type eq "1"){ print "Content-type: text/html\n\n"; foreach $num (@nums){$display = "$num"; print $display;} } if ($type eq "2"){ print "Content-type: text/html\n\n"; foreach $num (@nums){$display = ""; print $display;} } if ($type eq "3"){ print "Content-type: image/gif\n\n"; open (IMAGE, "$url/$nums[$query].$ext"); print ; close(IMAGE); } open(INF,$ip); foreach $i (){ chop($i); if ("$i" eq "$addr"){$t = 1}} if ($t eq "0"){ open(NIP, ">>$ip"); print NIP $addr."\n"; close(NIP); ++$count; open(NCOUNT, ">$file"); print NCOUNT $count; } close(INF);
Help.
#!/usr/bin/perl ###################################### # the perl line might need changing # # In order to find out where your # # server has perl, type: # # which perl # # at a telnet session to your server # # # # # ###################################### #------------------------------------------------------------ # # Version 2.0 # # This script is copyright 1999 Brian Taber # # Distribution of this script is unlimited # please visit http://www.tgd-computers.com/bst # to obtain this script. # # Please do not modify this script in any way. # If you have any suggestions or questions # for me on the script, please e-mail btaber@hotmail.com # # # # Remember to upload the script in ASCII format! # The permissions for the script must be set before use!! # Here is the command lines in UNIX # # chmod 755 counter.pl # chmod 666 counter.txt # chmod 666 counterip.txt # # # #------------------------------------------------------------ # Modify the 5 varibles below to suit your needs. # CAUTION! Do not remove the semi-colins ; # Or Quotes '' # 1 - This is the directory where the digits are kept, this must be the full path to the images: $url = 'URL' ; # 2 - This is the extension on the digits: $ext = 'gif' ; # 3 - This is the text file that contains the count: $file = 'counter.txt' ; # 4 - This is the text file that contains the IP addresses of the visitors: $ip = 'counterip.txt' ; # 5 - This tells the counter to use images or text numbers. The deafult is use text. # read the ReadMe text file on how to use each of them. the selections are: # 1 - Use SSI and display text # 2 - Use SSI and display images # 3 - Use regular IMG tag to display image $type = 1 ; # # # DO NOT MODIFY BELOW THIS LINE!!! #------------------------------------------------------------------------------- # $addr = "$ENV{'REMOTE_ADDR'}"; $query = $ENV{'QUERY_STRING'} -1; $t = 0; open(COUNT, $file); $count = ; close(COUNT); @nums = split(//, $count); if ($type eq "1"){ print "Content-type: text/html\n\n"; foreach $num (@nums){$display = "$num"; print $display;} } if ($type eq "2"){ print "Content-type: text/html\n\n"; foreach $num (@nums){$display = ""; print $display;} } if ($type eq "3"){ print "Content-type: image/gif\n\n"; open (IMAGE, "$url/$nums[$query].$ext"); print ; close(IMAGE); } open(INF,$ip); foreach $i (){ chop($i); if ("$i" eq "$addr"){$t = 1}} if ($t eq "0"){ open(NIP, ">>$ip"); print NIP $addr."\n"; close(NIP); ++$count; open(NCOUNT, ">$file"); print NCOUNT $count; } close(INF);
Help.
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
do you have a working example of this? it appears to me that all it is doing is outputing the contents of your perl script and not actually excuting it. since you're converting to php you might lookinto converting the perl script to php. it doesn't look to hard and im sure the people here would be willing to help in the conversion.
the perl script hasn't been executed but included as plain text.
take a look at the exec functions of php.
Since the perl-script is using CGI you have to provide the necessary variables. If you have php running as CGI, too, you should not have to worry about this.
If php is running as mod_php you have to export at least $_SERVER['REMOTE_ADDR'] and $_SERVER['QUERY_STRING']
putenv is one option. Another (maybe) is to invoke the script preceded by the variables (never tried this from a php-script
)
$exec should look like QUERY_STRING="" REMOTE_ADDR="127.0.0.1" /www/cgi-bin/counter.cgi
take a look at the exec functions of php.
Since the perl-script is using CGI you have to provide the necessary variables. If you have php running as CGI, too, you should not have to worry about this.
If php is running as mod_php you have to export at least $_SERVER['REMOTE_ADDR'] and $_SERVER['QUERY_STRING']
so that perl can find it as $ENV{'REMOTE_ADDR'} and $ENV{'QUERY_STRING'}.Note: Introduced in 4.1.0. In earlier versions, use $HTTP_SERVER_VARS.
putenv is one option. Another (maybe) is to invoke the script preceded by the variables (never tried this from a php-script
Code: Select all
$path2script = '/www/cgi-bin/counter.cgi';
$exec = 'QUERY_STRING="'.$_SERVERї'QUERY_STRING'].'" REMOTE_ADDR="'.$_SERVERї'REMOTE_ADDR'].'" '.$path2script;
passthru($exec);- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
maybe try shell_exec
Code: Select all
$count = shell_exec('path/to/file');
$count = str_replace( "Content-type: text/html", "", $count );
echo $count;- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
and if you want you can see what others have already done at places like hotscripts.com:DaZZleD wrote:you cold just make a counter of your own in php with mysql support... just a thought
http://www.hotscripts.com/PHP/Scripts_a ... /Counters/
Mac
First of all, I apologize for flogging what should be a dead horse.
Unfortunately, none of the above code worked, and I've now tried 9 different php based counters, and none of them worked well either (though I can appreciate that it was human error). I would also really like to just keep the current CGI counter I have, as it does everything I need.
Now then, someone suggested above posting the PERL code here.
Apparently, it supports "supports SSI and IMG tag".
Thanks for all of the help so far.
Unfortunately, none of the above code worked, and I've now tried 9 different php based counters, and none of them worked well either (though I can appreciate that it was human error). I would also really like to just keep the current CGI counter I have, as it does everything I need.
Now then, someone suggested above posting the PERL code here.
Apparently, it supports "supports SSI and IMG tag".
Code: Select all
# 1 - This is the directory where the digits are kept, this must be the full path to the images:
$url = 'URL' ;
# 2 - This is the extension on the digits:
$ext = 'gif' ;
# 3 - This is the text file that contains the count:
$file = 'counter.txt' ;
# 4 - This is the text file that contains the IP addresses of the visitors:
$ip = 'counterip.txt' ;
# 5 - This tells the counter to use images or text numbers. The deafult is use text.
# read the ReadMe text file on how to use each of them. the selections are:
# 1 - Use SSI and display text
# 2 - Use SSI and display images
# 3 - Use regular IMG tag to display image
$type = 1 ;
#
#
# DO NOT MODIFY BELOW THIS LINE!!!
#-------------------------------------------------------------------------------
#
$addr = "$ENV{'REMOTE_ADDR'}";
$query = $ENV{'QUERY_STRING'} -1;
$t = 0;
open(COUNT, $file); $count = <COUNT>; close(COUNT);
@nums = split(//, $count);
if ($type eq "1"){
print "Content-type: text/html\n\n";
foreach $num (@nums){$display = "$num"; print $display;}
}
if ($type eq "2"){
print "Content-type: text/html\n\n";
foreach $num (@nums){$display = "<img align=abscenter src=$url/$num.$ext>"; print $display;}
}
if ($type eq "3"){
print "Content-type: image/gif\n\n";
open (IMAGE, "$url/$numsї$query].$ext");
print <IMAGE>;
close(IMAGE);
}
open(INF,$ip);
foreach $i (<INF>){
chop($i);
if ("$i" eq "$addr"){$t = 1}}
if ($t eq "0"){
open(NIP, ">>$ip");
print NIP $addr."\n";
close(NIP);
++$count;
open(NCOUNT, ">$file");
print NCOUNT $count;
}
close(INF);Thanks for all of the help so far.
Try the passthru command. It should run your perl script and then show you the out put. I have not used it yet but i will be soon. The programers for the company I work for say that is what to use. We use shtml at the moment and are converting to php and that is what we will have to use for our banner ads.
maybe you should alter the script a bit for testing purposes
and try the passthru again.
Code: Select all
$addr = "$ENV{'REMOTE_ADDR'}";
die (print "Content-type: text/plain\n\ninvalid REMOTE_ADDR") if (length($addr) < 1);
$query = $ENV{'QUERY_STRING'}-1;Nothing happens. I assume therefore that the script is still not being run, but rather 'output' as it was before, but it just doesn't show up on the page.
Look, I feel bad wasting people's time on a stupid counter.
Can anyone recommend a good, simple PHP counter? I've had no luck at all...
Thank you for all of your help.
I'll figure it out someday...
Look, I feel bad wasting people's time on a stupid counter.
Can anyone recommend a good, simple PHP counter? I've had no luck at all...
Thank you for all of your help.
I'll figure it out someday...
as mentioned, http://www.hotscripts.com has some.
But one last try:
If you replace the whole contents of the perl-file byand still nothing happens, at least one of the following is probably true
But one last try:
If you replace the whole contents of the perl-file by
Code: Select all
#!/usr/bin/perl
print "hello world\n";- the path to the script is invalid. It must be the filesystem path as seen from where the script is running, e.g. if your script is located in /home/userA/www/counting.php passthru('cgi-bin/counter.cgi') will try to execute the file /home/userA/www/cgi-bin/counter.cgi
- the file has not the appropriate eXecute-flag set. Try perl /absolute/path/to/script instead
- Your script cannot acces the directory (also permission flags)
- you cannot access passthru or it is broken. Does passthru('ls'); generate output?