How to include other php files in templates

Tutorials for <a href="http://www.phpbbstyles.com/viewtopic.php?t=356">eXtreme Styles mod</a> for phpBB 2.0.

Moderator: Moderators

How to include other php files in templates

Postby PostBot on Wed Nov 26, 2003 10:56 am

How to include other php files in templates

To include local php file you can use usual include() functoin.
Path to file is relative to forum root directory. Use variable $phpbb_root_path to make sure that path is always relative to phpbb root path.



If your forum is in directory /phpBB2/ and you want to include file /my_website/header.php you should use this code:
Code: Select all
<?php include($phpbb_root_path . '../my_website/header.php'); ?>




If you want to include remote file via http you should use function readfile():
Code: Select all
<?php @readfile('http://somewhere/somefile.php'); ?>

Remote files are treated as html files, not as php files. And you'd better add @ before function to suppress warning in case if remote file is temporary unavailable.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

still a little problem

Postby videokid on Thu Feb 19, 2004 11:11 am

Hi,

great mod, but I experience next problem

Warning: readfile() [function.readfile]: php_network_getaddresses: gethostbyname failed in D:\InetPub\Videostore\forum\includes\template.php(478) : eval()'d code on line 258

Warning: readfile(http://www.video-store.be/videokid/forum/random_txt.php) [function.readfile]: failed to create stream: No error in D:\InetPub\Videostore\forum\includes\template.php(478) : eval()'d code on line 258


First I tried to inlcude it but I get the message

error: cannot open file


then I tried to use the function readfile, now I've added the '@', so now I don't get the error message anymore. Other php files seem to work...

Any ideas, thank you very much...

PS: I'm not a php programmer....
videokid
Registered User
Registered User
 
Posts: 2
Joined: Thu Feb 19, 2004 11:00 am

Postby PostBot on Thu Feb 19, 2004 1:44 pm

Your host can't connect to that server. Probably sockets are disabled.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

thanks

Postby videokid on Mon Mar 15, 2004 2:07 pm

ok, thanks for your reply, nothing to do about it, due security reasons it's that way.

Kind regards
videokid
Registered User
Registered User
 
Posts: 2
Joined: Thu Feb 19, 2004 11:00 am

Postby ZandPilooT on Sat Apr 10, 2004 11:46 pm

I've tried to integrate a php script into my forum template, but I just can't get it right.
I think you might know this code :wink:
Code: Select all
<?php

$stats_host = "127.0.0.1";
$stats_port = 1228;

Header("Pragma: no-cache");
Header("Cache-Control: no-cache");
Header("Expires: Thu Jan  1 00:00:00 1970");

function DoConnect()
{
   global $stats_host, $stats_port, $socket;
   $socket = fsockopen($stats_host,$stats_port);
}


?><!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="Author" content="cyberalien@users.sourceforge.net">
<meta name="Generator" content="PHP <?php echo phpversion(); ?>">
<title>Network Stats Template</title>
<style type="text/css">
<!--
BODY, TD                 {font-family: Verdana; font-size:12px; color:#000000}
A:link, A:active       {color:#FF8000; text-decoration:none;}
A:visited                {color:#FF4000; text-decoration:none;}
A:hover                  {color:#FF0000; text-decoration:underline;}
//-->
</style>
</head>
<body bgcolor=#FFFFFF marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">
<center>
<br>
<h1>This is a template for servers list</h1>

<?php

DoConnect();
if(!$socket)
{
   echo "Error: cannot connect to main server";
}else
{
   $data=trim(fgets($socket,1024));
   list($num_servers,$num_users,$max_users,$num_files,$num_bytes)= split (" ", $data, 5);
   for($i=0;$i<$num_servers;$i++)
   {
      $data=trim(fgets($socket,1024));
      list($d_host[$i],$d_port[$i],$d_users[$i],$d_max_users[$i],$d_files[$i],$d_bytes[$i],$d_elite[$i])= split(" ",$data, 7);
   }
   fclose($socket);

?>
<table border=0 cellspacing=1 cellpadding=0 bgcolor=#808080>
<tr height=20>
<td bgcolor=#70C0FF width=30>&nbsp;</td>
<td bgcolor=#70C0FF align=center width=350>Host Name</td>
<td bgcolor=#70C0FF align=center width=60>Port</td>
<td bgcolor=#70C0FF align=center width=75>Users</td>
<td bgcolor=#70C0FF align=center width=100>Users Limit</td>
<td bgcolor=#70C0FF align=center width=80>Files</td>
<td bgcolor=#70C0FF align=center width=85>GB</td>
<td bgcolor=#70C0FF align=center width=100>Elite</td>
</tr>
<?php

   for($i=0;$i<$num_servers;$i++)
   {
      if(($i%2)==0) $clr="#FFC070";
      else $clr="#FFD078";
      echo "<!-- servers list entry -->\n";
      echo " <tr height=16>\n";
      $j=$i+1;
      echo " <td bgcolor={$clr} align=right>{$j}.&nbsp;</td>\n";
      echo " <td bgcolor={$clr}>&nbsp;{$d_host[$i]}</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_port[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_users[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_max_users[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_files[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_bytes[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr}>&nbsp;{$d_elite[$i]}</td>\n";
      echo "</tr>";
   }
   echo "<!-- end servers list entries -->\n";
   echo "<tr height=20>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=center><b>Total:</b></td>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_users}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$max_users}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_files}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_bytes}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo "</tr>\n";
?>
</table></center>
</body>
</html>

<?php

}

?>


Can you please help me out with this one?
Like I said, I've tried some things, but it keeps messing up the page. And I have verry verry little knowledge of php.
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Postby PostBot on Sat Apr 10, 2004 11:51 pm

Templates are included inside function, so you should declare variables $stats_host, $stats_port, $socket as global in your main script after <?php
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ZandPilooT on Sun Apr 11, 2004 12:11 am

The code i've posted is the report.php code and i want it to have the same look as the template of the forum.
Must I declare the $stats_host, $stats_port, $socket variables in index.php of the forum?
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Postby PostBot on Sun Apr 11, 2004 12:39 am

no need to. just declare it as global after <?php in that tpl file
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ZandPilooT on Mon Apr 12, 2004 10:36 pm

I've placed some code in the portal_body.tpl. Not in the portal.php. When I refresh, it returns absolutely nothing.

This is what I placed in portal_body.tpl:

Code: Select all
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="forumline">
              <tr>
                <th height="25" class="catHead"><span class="genmed"><b>Live
                  Stats </b></span></th>
              </tr>
              <tr>
                <td class="row1">
            <?php

$stats_host = "127.0.0.1";
$stats_port = 1228;

function DoConnect()
{
   global $stats_host, $stats_port, $socket;
   $socket = fsockopen($stats_host,$stats_port);
}


?>
<?php

DoConnect();
if(!$socket)
{
   echo "Error: cannot connect to main server";
}else
{
   $data=trim(fgets($socket,1024));
   list($num_servers,$num_users,$max_users,$num_files,$num_bytes)= split (" ", $data, 5);
   for($i=0;$i<$num_servers;$i++)
   {
      $data=trim(fgets($socket,1024));
      list($d_host[$i],$d_port[$i],$d_users[$i],$d_max_users[$i],$d_files[$i],$d_bytes[$i],$d_elite[$i])= split(" ",$data, 7);
   }
   fclose($socket);

?>
<table border=0 cellspacing=1 cellpadding=0 bgcolor=#808080>
<tr height=20>
<td bgcolor=#70C0FF width=30>&nbsp;</td>
<td bgcolor=#70C0FF align=center width=350>Host Name</td>
<td bgcolor=#70C0FF align=center width=60>Port</td>
<td bgcolor=#70C0FF align=center width=75>Users</td>
<td bgcolor=#70C0FF align=center width=100>Users Limit</td>
<td bgcolor=#70C0FF align=center width=80>Files</td>
<td bgcolor=#70C0FF align=center width=85>GB</td>
<td bgcolor=#70C0FF align=center width=100>Elite</td>
</tr>
<?php

   for($i=0;$i<$num_servers;$i++)
   {
      if(($i%2)==0) $clr="#FFC070";
      else $clr="#FFD078";
      echo "<!-- servers list entry -->\n";
      echo " <tr height=16>\n";
      $j=$i+1;
      echo " <td bgcolor={$clr} align=right>{$j}.&nbsp;</td>\n";
      echo " <td bgcolor={$clr}>&nbsp;{$d_host[$i]}</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_port[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_users[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_max_users[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_files[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr} align=right>{$d_bytes[$i]}&nbsp;</td>\n";
      echo " <td bgcolor={$clr}>&nbsp;{$d_elite[$i]}</td>\n";
      echo "</tr>";
   }
   echo "<!-- end servers list entries -->\n";
   echo "<tr height=20>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=center><b>Total:</b></td>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_users}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$max_users}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_files}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0 align=right>{$num_bytes}&nbsp;</td>\n";
   echo " <td bgcolor=#FFA0E0>&nbsp;</td>\n";
   echo "</tr>\n";
?>
</table>
            </td>
              </tr>
            </table>
      
      <br />
I'm still trying to finish chapter 2 of "php for dummies" :)
[HollandsGlorie Network] | [ModelSpoorBouw Forum]
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Postby PostBot on Mon Apr 12, 2004 11:38 pm

You are missing } in that script.
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ZandPilooT on Tue Apr 13, 2004 1:12 pm

Hmm, I placed it now, but there's still nothing to see.
I'm still trying to finish chapter 2 of "php for dummies" :)
[HollandsGlorie Network] | [ModelSpoorBouw Forum]
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Postby PostBot on Tue Apr 13, 2004 3:16 pm

Where is that forum and what style are you editing?
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ZandPilooT on Wed Apr 14, 2004 2:33 am

The page I'm editting is on my testing server here at home ( http://zandpiloot.dynu.com/hollandsglorie ) but it's not always online. When everything works fine, I upload the files to the main server :roll:
The template I'm editting is FI Blue 3D from Forum Images.
I'm still trying to finish chapter 2 of "php for dummies" :)
[HollandsGlorie Network] | [ModelSpoorBouw Forum]
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Postby PostBot on Wed Apr 14, 2004 1:33 pm

You forgot to declare variables as global.

Before this:
Code: Select all
$stats_host = "zandpiloot.dynu.com";
add this:
Code: Select all
global $stats_host, $stats_port, $socket;
Do NOT pm me, I don't visit this forum anymore, don't own it, don't provide any support and don't moderate.
User avatar
PostBot
Moderator
Moderator
 
Posts: 10659
Joined: Sat Aug 02, 2003 3:52 pm
Location: Mars

Postby ZandPilooT on Wed Apr 14, 2004 1:44 pm

Nope, doesn't work overhere???? :?

I've made a new page with tpl file and tried to place the header and footer in it. It works so so, but at least it connects to the server and retrieves the data. But it returns the data in a very strange order.
http://zandpiloot.dynu.com/hollandsglorie/slavanap.php
I'm still trying to finish chapter 2 of "php for dummies" :)
[HollandsGlorie Network] | [ModelSpoorBouw Forum]
ZandPilooT
Registered User
Registered User
 
Posts: 7
Joined: Sat Apr 10, 2004 11:32 pm
Location: Dorrestad.nl

Next

Return to eXtreme Styles mod tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron