Thanks tons,
Ramsey
Wherever you want the script to be inserted do this:
<?php
include("cgifile.pl")
?>
Welcome to WebmasterWorld!
If you are running PHP [php.net] on Apache [httpd.apache.org] you could use virtual() [php.net] to include the output with a subrequest.
include() [php.net] will not work when you include a local script using its local filename since PHP [php.net] switches back to HTML mode and just loads the file spits out the parts that are HTML and executes the PHP [php.net] parts. When you use include() [php.net] with a URI then PHP [php.net] will request that URI and include the output of that request. So you would need to use include("http://your.server.tld/path/to/cgi.script");
Andreas
Thanks for the helpful tips. I don't know much about my server (I *do* believe it's an Apache, but I may be wrong and I don't know any versions or anything.) The hosting service provider is Netfirms, if anybody has had any dealings with them and might be able to help.
I thought I had PHP access, but I know don't have any database backups (like MySQL or others) and I have never used any PHP programing. But when I tried to do the PHP "Include" I got the following error:
---
Fatal error: Call to undefined function: phpinclude() in photocontest_test.php on line 221
---
So I don't know if that means that I don't have PHP or if the code I used was wrong or what. I used the full [myserver.com...] inside the include code. Should I have used the path instead? Is there something else I should be (or shouldn't, for that matter) be doing?
Thanks for all your help so far!
Ramsey
---
Warning: php_hostconnect: connect failed in photocontest_test.php on line 237
Warning: Failed opening 'http:*//www.mysite.net/cgi-bin/photocontest/conformation.pl' for inclusion (include_path='.:/usr/local/nf/lib/php') in photocontest_test.php on line 237
---
Any idea what they mean? (And you can also go to <snip> to see the file in question. I'm trying to have the contents of the cgi file displayed in the right hand column of the table (the white background area, where the error msg is displayed).
Thanks for the help so much so far. I think I'm on the right track, and you have all been so helpful! Thanks again.
Ramsey
[edited by: jatar_k at 2:27 pm (utc) on Feb. 10, 2003]
[edit reason] no urls please [/edit]
Check that the URI you try to open returns something valid by requesting it using your browser.
Andreas
Ramsey
[edited by: jatar_k at 3:01 am (utc) on Feb. 11, 2003]
[edit reason] no urls please [/edit]
[bugs.php.net...]
Andreas
<?php
$fp = fsockopen ("127.0.0.1", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /horses-cgi-script HTTP/1.0\r\n".
"Host: www.somehorses.com\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
example taken from the PHP [php.net] manual - fsockopen() [php.net]
This will open a connection to your local server using fsockopen() [php.net]. If the connection is established it will send a request for the horses-cgi-script using fputs() [php.net]. If you are using name based virtual hosting then you need to set the Host: field to contain your domain name. It will then loop and read chunks of data using fgets() [php.net] and echo() [php.net] them. If there is nothing left to read feof() [php.net] will be true and it will close the connection using fclose() [php.net].
Andreas
I thought I'd try some simple things to see if I could get them to work before I work on my cgi-file. <snip> is a very simple page where I'm trying to include an HTML page found at <snip> and I've been UNsuccessful w/ the following code:
<?php
$fp = fsockopen ("udp://00.00.00.00", 21, $errno, $errstr);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: /simplephptest2.html\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
209.171.43.28 is my IP, and 21 is my initial port #. I keep getting the following error: Invalid argument (22) ... and it's DRIVING ME NUTS! I've even deleted all code through line 22 and still see this error. Check the above pages to see for yourself. I'm clueless! (And so far apparently helpless too!)
[edited by: jatar_k at 3:03 am (utc) on Feb. 11, 2003]
[edit reason] Read TOS [webmasterworld.com] [/edit]
<?php
$fp = fsockopen ("209.171.43.28", 21, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /simplephptest2.html HTTP/1.0\r\n".
"Host: www.domain.net\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
and get the same 22 error. Then, changed code to :
<?php
$fp = fsockopen ("udp://209.171.43.28", 21, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /simplephptest2.html HTTP/1.0\r\n".
"Host: www.domain.net\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
(simply adding the udp://) and get a 500 Internal Server Error... I'm completely socked!
[edited by: jatar_k at 3:03 am (utc) on Feb. 11, 2003]
Andreas
[edited by: jatar_k at 3:04 am (utc) on Feb. 11, 2003]
<!--#include file="simpletest2.html" -->
If it doesn't work at first, just add these lines to your .HTACCESS file to process all .htm & .html as shtml
AddType text/html .shtml .htm .html
AddHandler server-parsed .shtml .htm .html
I mean unless you just insist on using PHP to solve this?
you can also trigger cgi's the same way with SSI
<!--#exec cgi="/cgi-bin/cginame.cgi" -->
or
<!--#include virtual="/cgi-bin/cginame.cgi" -->
[edited by: amznVibe at 6:01 pm (utc) on Feb. 10, 2003]
I suppose that was my fault for bringing it up in msg #2 [webmasterworld.com]
[edited by: Birdman at 6:14 pm (utc) on Feb. 10, 2003]
<?php
$fp = fsockopen ("www.aaroncarter.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /index.php\r\n HTTP/1.0\r\n\r\n".
"Host: www.aaroncarter.com\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
This doesnīt.
<?php
$fp = fsockopen ("www.yoursite.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /\r\n HTTP/1.0\r\n\r\n".
"Host: www.yoursite.net\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
And this does work again:
telnet www.yoursite.net 80
Trying 209.171.43.28...
Connected to ip28-43-171-209.toro1.na.psigh.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: www.yoursite.net
HTTP/1.1 200 OK
Date: Mon, 10 Feb 2003 18:11:04 GMT
Server: Apache/1.3.26 (Unix) mod_perl/1.26 PHP/4.0.4pl1 mod_ssl/2.8.10 OpenSSL/0.9.6a
Last-Modified: Mon, 13 Jan 2003 18:31:13 GMT
ETag: "1729902-658-3e2305f1"
Accept-Ranges: bytes
Connection: close
Content-Type: text/html
<HTML>
Andreas
[edited by: jatar_k at 7:28 pm (utc) on April 16, 2003]
<snip>
This looks like the way to go. I'm going to work on that cgi include now. I looked on my server, don't have an .htacces file, so should I create one and if so, how? Is there a way to make all .HTML files read as .SHTML files? Thanks for putting up with my stupidity!
[edited by: jatar_k at 3:06 am (utc) on Feb. 11, 2003]
Does this mean my permissions are set incorrectly? *sooo confused - went to school for graphic design, not computer programing*
I just like the PHP stuff better because it kind of seemed neater at the time.
Andreas - I tried the two different php code snippets you just listed and BOTH of them gave me the "22" error. I also really haven't the foggiest of ideas what info you got from the telnet bit.
*sigh* maybe I'll just never get this....
[edited by: jatar_k at 3:06 am (utc) on Feb. 11, 2003]
# make sure certain files are never shown in an open directory
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*# turn on important server options
Options FollowSymLinks Includes ExecCGI# support various CGI extensions:
AddType application/x-httpd-cgi .cgi .pl# support SSI parsing on most HTML types:
AddType text/html .shtml .htm .html
AddHandler server-parsed .shtml .htm .html# encourage browsers/proxies to cache image files for a month, to keep bandwidth down
ExpiresActive on
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"# return correct content-type for certain images:
AddType image/x-xbitmap .xbm .XBM
AddType image/bmp .bmp .BMP
AddType image/x-icon .ico# always a good idea to have a custom 404 error message
ErrorDocument 404 /missing.htm<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
an error occurred while processing this directive
if you are trying to do a cgi include, you'll have to try the other technique since you are getting the above message...
if you are using <!--#exec cgi="/cgi-bin/cginame.cgi" -->
then switch it to <!--#include virtual="/cgi-bin/cginame.cgi" -->
and see if that clears up the problem
also, when you install the above .htaccess file, you will be able to use the extension of .htm or .html instead of .shtml
then switch it to <!--#include virtual="/cgi-bin/cginame.cgi" -->
and see if that clears up the problem
also, when you install the above .htaccess file, you will be able to use the extension of .htm or .html instead of .shtml
------- Total Astonishment -------- :-)
Using the include virtual worked like a charm. I copied the above text, named it .htaccess and uploaded it to my www/ dir on my server, but I still need to type filename.shtml to get the SSI's to work properly. Did I miss something?
Thanks so much for everyone putting up with me. I've tried other forums for help and never found a community or group of people who are so helpful and know their stuff so well. Thanks again!
Andreas we still didn't help with the problem of .htm and .html not being treated as .shtml
Can you spot any problems with my sample htaccess file above?
These lines should have fixed that issue, no?
AddType text/html .shtml .htm .html
AddHandler server-parsed .shtml .htm .html
ah wait, I think I spotted something, try adding this line to .htaccess, or replace the above AddType with it AddType text/x-server-parsed-html .html .htm