View Full Version : Can php be used in HTML?
Me2Be
Wed 10th Jan '01, 2:25pm
Is this possible?
I'd like to use my 'active topics' hack I have working on server #1, and have the output shown on an HTML page (like through SSI) on server #2 on an HTML page.
Mike Sullivan
Wed 10th Jan '01, 2:34pm
HTML code here<BR>
<?php
echo "PHP code here<BR>";
?>
More HTML code
JimF
Wed 10th Jan '01, 2:41pm
You also have to rename the extension of your page to .php so the PHP engine knows to turn on. Or you can use .htaccess to parse .html extensions as PHP.
-jim
Me2Be
Wed 10th Jan '01, 2:45pm
How would this work cross server? I understand how to get it to work if it is on the same server, but on different servers?
On the UBB (way back when), Capps had me do this to get the cgi cross server:
#!/path/to/perl
use LWP::Simple;
$stuff = get("http://www.domain.com/path/to/active.cgi");
print "Content-type: text/html\n\n$stuff";
exit;
JohnM
Wed 10th Jan '01, 3:03pm
Originally posted by Me2Be
#!/path/to/perl
use LWP::Simple;
$stuff = get("http://www.domain.com/path/to/active.cgi");
print "Content-type: text/html\n\n$stuff";
exit;
In PHP that'd be:
echo implode("",file("http://www.domain.com/path/to/active.cgi"));
Me2Be
Wed 10th Jan '01, 3:47pm
Originally posted by JohnM
Originally posted by Me2Be
#!/path/to/perl
use LWP::Simple;
$stuff = get("http://www.domain.com/path/to/active.cgi");
print "Content-type: text/html\n\n$stuff";
exit;
In PHP that'd be:
echo implode("",file("http://www.domain.com/path/to/active.cgi"));
Thanks JohnM!
How exactly would I add that into the HTML then? Would I incorporate what Ed originally said? (Still learning here!)
Mike Sullivan
Wed 10th Jan '01, 3:52pm
Put
<?php
echo implode("",file("http://www.domain.com/path/to/active.cgi"));
?>Where ever you want the list to be displayed.
Me2Be
Wed 10th Jan '01, 4:00pm
Okay, cross your fingers! I'm going to try it!
Me2Be
Wed 10th Jan '01, 4:30pm
Okay, a little complication here :)
The way my active file was written has actually 5 different actions ($action=="todaysactivethreads", $action=="todaysactiveusers"), etc.
How would I change what you gave me or do I have to make it a separate script?
Mike Sullivan
Wed 10th Jan '01, 4:33pm
echo implode("",file("http://www.domain.com/path/to/active.cgi?action=whatever"));
You can call it more than once if you want (5 times, once for each action for example)
Me2Be
Wed 10th Jan '01, 4:50pm
Nope, getting a blank space.
When I run the file from the browser is does bring up the last ten threads, but when I embed it into an HTML file, it comes up blank (though I see the php code in the source).
This is what I have, do I have the context wrong?.
<html>
<head>
</head>
<body>
<?php
echo implode("",file("http://domain.com/vbinfo.php?action=lasttenthreads"));
?>
</body>
</html>
JimF
Wed 10th Jan '01, 5:07pm
When I run the file from the browser is does bring up the last ten threads, but when I embed it into an HTML file, it comes up blank (though I see the php code in the source).
Carrie, does your file still have an .html extension? Otherwise it won't parse the PHP - which it doesn't seem to be doing.
-jim
Me2Be
Wed 10th Jan '01, 5:09pm
Originally posted by JimF
Carrie, does your file still have an .html extension? Otherwise it won't parse the PHP - which it doesn't seem to be doing.
[/B]
Yes it does have an .html extension. I have SSI for CGI working on these pages, but is there some place I need to tell it to have php also to work on these pages?
JimF
Wed 10th Jan '01, 5:17pm
Yes, either rename it to .php - or in your .htaccess file put the following code... Actually, I forget what the proper code is. Hrumph. I'm sure someone here knows, but I'll do some digging anyway.
-jim
Mike Sullivan
Wed 10th Jan '01, 5:21pm
Yes it does have an .html extension. I have SSI for CGI working on these pages, but is there some place I need to tell it to have php also to work on these pages?Unfortunately, I don't think you can mix PHP with SSI. So lets try this.
Create activeinclude.php (anything with .php extension), and put this in it:
<?php
echo implode("",file("http://domain.com/vbinfo.php?action=lasttenthreads"));
?>
Then just use SSI to call it -- <!--#include virtual="activeinclude.php" --> (I think that's right. I don't really use SSI anymore)
Me2Be
Wed 10th Jan '01, 5:21pm
Thanks for your help, I'd love the .htaccess code to put in there!
I'd prefer not to rename my file to *.php because it is my main site page (not the board) and it receives quite a few page views a day and I don't want to run up my load time!
Thanks everyone for your help!!
JohnM
Wed 10th Jan '01, 5:25pm
I'm pretty sure the htaccess code he was referring to was to parse .html files as php. Basically the same as renaming it to .php anyway.
Me2Be
Wed 10th Jan '01, 5:25pm
Originally posted by Ed Sullivan
Create activeinclude.php (anything with .php extension), and put this in it:
<?php
echo implode("",file("http://domain.com/vbinfo.php?action=lasttenthreads"));
?>
Then just use SSI to call it -- <!--#include virtual="activeinclude.php" --> (I think that's right. I don't really use SSI anymore) [/B]
You are a genius!!! It worked!!!!!!!!
vBulletin® v3.8.0 Beta 3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.