Including PHP in a HTML page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
i2Paq
Forum Newbie
Posts: 2
Joined: Mon Nov 18, 2002 3:12 pm
Location: The Netherlands

Including PHP in a HTML page

Post by i2Paq »

I have a php-script which will, if added correctly to an HTML page, display the users online at that moment on your site.
This comes in handy when you do not have MySql support.

This online.php uses also an online.txt to registers some things.
It’s a part of a forum which is also written in PHP and the maker has given me permission to use this online.php a part from his PHP-forum.

The question is this, how do I include this online.php in a HTML page?

If you not have guess already, I’m an absolute n00b to PHP.
If requested I can display or e-mail this script.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

<?
require("/absolute/path/to/online.php");
?>

Find the absolute path to the file (it won't be http://url.com/file or anything like that)...

Fill that path in and that should do it.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

can't

Post by phpScott »

you can't include a php page in an html page. Your html page will have to be saved as a php page otherwise the php you have included in that page will not be parsed at all.

Even if you just do

Code: Select all

&lt;?php
require("/absolute/path/to/online.php");

?&gt;
at the top of your page or where ever you want to include that file your page that is includeing tha file will have to be saved as a php page.

phpScott
skyhawk133
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 10:25 pm
Location: Rio Rancho, NM

Post by skyhawk133 »

Unless however you have enough control over your server to add the HTML MIME type to types of pages that are parsed using the PHP engine...

I did that for about 6 months during the period that google and other engines updated the links to my new pages... same concept though.
i2Paq
Forum Newbie
Posts: 2
Joined: Mon Nov 18, 2002 3:12 pm
Location: The Netherlands

Post by i2Paq »

I use;

<div align="center"><iframe frameborder=0 src="http://www.i2paq.org/forum/online/online.php" width="130" height="400"></iframe></div>

but then I get these errors;
Warning: Unable to access online/online.txt in /home/sites/site30/web/i2paq/forum/online/online.php on line 20

Warning: fopen("online/online.txt", "r") - No such file or directory in /home/sites/site30/web/i2paq/forum/online/online.php on line 20

Warning: stat failed for online/online.txt (errno=2 - No such file or directory) in /home/sites/site30/web/i2paq/forum/online/online.php on line 21

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 21

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 22

Warning: fopen("online/online.txt", "w") - No such file or directory in /home/sites/site30/web/i2paq/forum/online/online.php on line 27

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 28

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 29

Warning: Unable to access online/online.txt in /home/sites/site30/web/i2paq/forum/online/online.php on line 57

Warning: fopen("online/online.txt", "r") - No such file or directory in /home/sites/site30/web/i2paq/forum/online/online.php on line 57

Warning: stat failed for online/online.txt (errno=2 - No such file or directory) in /home/sites/site30/web/i2paq/forum/online/online.php on line 58

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 58

Warning: Supplied argument is not a valid File-Handle resource in /home/sites/site30/web/i2paq/forum/online/online.php on line 59

It is the same file on the same location that I use in my Forum at http://www.i2paq.org/forum/index.php
Check the top where it say's "1 users online"

I also found in the header.php of this forum something that adresses to online.php.

include("online/online.php");
echo"<table cellspacing=1 cellpadding=4 border=0 width=100%>\n";
echo"<tr>\n";
echo"<td width=50% align=\"left\"><h2>$title</h2></td>\n";
echo"<td width=30% valign=\"top\">\n";
if($mode=='index'){
echo"<h6>$n_u_online $user_online<br>\n";
include("online/online_member.php");

If needed I can send anyone the files.

What am I missing or doing wrong?

Again, I'm not in writing PHP, but I do know how to change scripts.
Post Reply