Custom Page With PHP In It.

Discussion forum for MOD Writers regarding MOD Development.
crazydiamond
Registered User
Posts: 23
Joined: Mon Jan 31, 2011 12:43 am

Re: Custom Page With PHP In It.

Post by crazydiamond »

Thanks t_backoff,

Forget the external php then for a minute until I get permission to use it.
I have a script for tide information that runs local and works fine from within the browser if I point directly to the file.

Code: Select all

http://localhost/phpbb/todaysTide.php
That loads great in the browser and does as it is supposed to and shows todays tides from a file that contains the months tide information.

How would I go about implementing that into my custom page please.

A step by step would be great
skafreak
Registered User
Posts: 23
Joined: Sun Feb 22, 2004 3:00 pm

Re: Custom Page With PHP In It.

Post by skafreak »

OK, I got this working now.

First you must enable PHP use within your Admin Control Panel. (This was something I was missing before).
Second you setup your main php file that will go in the root directory, we will call this main.php. Then place this code in that file.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Title Here');

$template->set_filenames(array(
    'body' => 'main_body.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
Change 'Title Here' to the title of the page and 'main_body.html' to the name of the template page that we will make next. So, now make main_body.html and place it in the styles/yourstyle/template/ folder. Then put this code in that file.

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>About Us</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
         We were founded this year to bring you the best forum on the Internet!
         
         We promise to do the following:
         <ul>
            <li>Provide new content</li>
            <li>provide a friendly atmosphere</li>
            <li>Provide an environment where you can have fun!</li>
         </ul>
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDEPHP main2.php -->
<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
You can adjust html and whatnot here. You also place

Code: Select all

<!--INCLUDEPHP main2.php -->
here
which points to your full php file. Create main2.php and place it in your root directory and add whatever php code you want.
Finally, login to your Admin Control Panel select the Styles tab, then Templates on the left, then refresh the template you are using.
That should do the trick.
crazydiamond
Registered User
Posts: 23
Joined: Mon Jan 31, 2011 12:43 am

Re: Custom Page With PHP In It.

Post by crazydiamond »

Hey skafreak, so glad you are having results.

I had done all what you posted a few days ago but still not having results with mine.

My page will load my
todaytide.php
but give unexpected results because I think the php is different syntax.

It tells me that the page needs refreshing, this is an error message from the script I am using.
Kinda sucks and is prob down to different syntax.

At a loose end now and am prob gonna ditch the phpbb custom pages idea and just design my own using dreamweaver.
I am gutted, but I will post up what my script does incase someone can spot a problem.

File todaytide.php

Code: Select all

<?php
require_once("/tides_processor.php"); tides(0);
?>
File tides_processor.php

Code: Select all

<?php
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//                                 Tide Processor                               //
$SCVersion=                           "V2.02"                                  ;//
//                                  by Al Rooker                                //
//                       www.NewtonAndNoss.com/weather/tech/                    //
//                                                                              //
//  Subscribe to my Weather Tech e-mail list for updates and new scripts etc!!  //
//                                                                              //
// This script is free for non commercial use only. If you use it on your site  //
// please feel free to give me credit and a link back to my site! Thanks.       //
//                                                                              //
// What does this script do? Well it takes your tideprediction.html file and    //
// turns the data into something you can actually use, and layout as you like!  //
//                                                                              //
// 1. Change the settings below, then upload this file anywhere on your site.   //
// 2. Upload the moon icons to where ever you like, then set their URL below.   //
// 3. On any php page on your site where you want to display tides add the      //
//    following and change to your actual server path!;                         //
//    require_once("/home/user/www/tides_processor.php");                       //
// 4. Where ever you want to display a tide record add the following;           //
//    <! tides(0); !>  (replace ! with ?) The number "0" means today. So this   //
//    would display today's tides. "1" will display tomorrow's tides,  and      //
//    "2" will display the next day and so on, up to about 20. It won't display //
//    tide times from the past so "0" is always today.                          //
// 5. Where ever you want to display a sun & moon record add the following;     //
//    <! sunmoon(0); !>  (replace ! with ?). The numbering is the same as above.//
//    If you do not want to include the date add ,nodate like this;             //
//    <! sunmoon(2,nodate); !>                                                  //
//                                                                              //
//                                                                              //
//   Set the server path to your tideprediction.html file                       //
$tidefile = "http://www.tbyc.org/weather/tideprediction.html";                                   //
//                                                                              //
//   Set the URL to the moon icons - no trailing slash                          //
$moonimg = "icons";                                                           //
//                                                                              //
//   If your tide dates include years (Monday 2008-09-10) change this to "yes"  //
$yearDate = "yes";                                                               //
//                                                                              //
//   You can convert "Rising & Falling" format to standard "High & Low"         //
//   by changing the following to "yes".                                        //
$convertRF = "no";                                                              //
//                                                                              //                                                                             //
//   If you do not want to show moon phase icons in tides put "yes" below       //
$TmoonPhaseOff = "no";                                                          //
//   If you do not want to show moon phase icons in Sun & Moon times put "yes"  //
$SmoonPhaseOff = "no";                                                          //
//                                                                              //                                                           //
//                                                                              //
//                 TRANSLATE FROM ENGLISH TO OTHER LANGUAGE                     //
//   If you want to translate from English to another language.....             //
//   Replace the following words                                                //
$translate = array("High Tide", "Low Tide", "Rising", "Falling", "Sunrise", "Sunset", "Moonrise", "Moonset");               //                                                                             //
//   Replace month names                                                        //
$months = array(" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//   Replace day names                                                          //
$transDay = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
//==============================================================================//
//======================= Nothing Else To Change ===============================//
//================== No user servicable parts inside :) ========================//
//==============================================================================//
//
function tides($numb = 0, $echoOff = 0) 
{
global $tidefile;
global $moonimg;
global $convertRF;
global $yearDate;
global $TmoonPhaseOff;
global $translate;
global $months;
global $transDay;

// Get tide file
error_reporting(0);
$tideD = implode('', file($tidefile));
if ($tideD == false)
{
// If there is no data we assume the tide file is currently being uploaded!
echo "<font color = \"red\">Tide data is being updated. Please refresh the page.</font>";
}
// Time & default words
$time = time();
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$tideWords = array("High Tide", "Low Tide", "Rising", "Falling");
//
// Get tide records by date, cut to length and split
// If year is included in date
if ($yearDate == "yes")
{
$tidedate = strstr($tideD, date("l Y-m-d", $time+(86400*$numb)));
$tideEnd = strpos($tideD, date("l Y-m-d", $time+(86400*($numb+1))));
}else{
$tidedate = strstr($tideD, date("l m-d", $time+(86400*$numb)));
$tideEnd = strpos($tideD, date("l m-d", $time+(86400*($numb+1))));
}
// The last tide will not show because it is not followed by a date. So we will
// set the end possition to a fixed leangth
if (!$tideEnd == false)
{
$tide = substr($tidedate, 0, $tideEnd);
}else{
$tide = substr($tidedate, 0, 280);
}
// Check if tides are in rising/falling format
if (strstr($tide, "Rising"))
{
$risingFormat = "yes";
//$tide = substr($tidedate, 0, $tideEnd);
}
$tide = explode("\n", $tide);
// Check if sunrise info is included
if (strstr($tide[1], "Sunrise"))
{
$tide = $tide[0]."|".$tide[3]."|".$tide[4]."|".$tide[5]."|".$tide[6]."|".$tide[7]."|".$tide[8]."|".$tide[9]."|".$tide[10];
$tide = explode("|", $tide);
}else{
$tide = $tide[0]."|".$tide[1]."|".$tide[2]."|".$tide[3]."|".$tide[4]."|".$tide[5]."|".$tide[6]."|".$tide[7]."|".$tide[8];
$tide = explode("|", $tide); 
}
// Convert date format to short day and full month names (UK format)
if ($yearDate == "yes")
{
$tideraw1 = $tide[0];
$dateraw = str_replace(" ","-", $tideraw1);
$dateraw = explode("-", $dateraw);
// Fix missing months on month numbers preseded by 0 with years in date
if (strlen($dateraw[2]) == 2 && substr($dateraw[2],0,1) == 0)
{
$dateraw[1] = substr($dateraw[2],1,1);
}
$daterawM = $months[$dateraw[2]];
}else{
$tideraw1 = $tide[0];
$dateraw = str_replace(" ","-", $tideraw1);
$dateraw = explode("-", $dateraw);
// Fix missing months on month numbers preseded by 0
if (strlen($dateraw[1]) == 2 && substr($dateraw[1],0,1) == 0)
{
$dateraw[1] = substr($dateraw[1],1,1);
}
$daterawM = $months[$dateraw[1]];
}
// translate days
$Day =str_replace($days, $transDay, $dateraw[0]);
if ($yearDate == "yes")
{
$dformat = substr($Day,0,3)." ".$dateraw[3]." ".$daterawM;
}else{
$dformat = substr($Day,0,3)." ".$dateraw[2]." ".$daterawM;
}
// Get moon details and show icons
if ($TmoonPhaseOff !== "yes")
{
$mooninfo= "$dateraw[0] $dateraw[1]-$dateraw[2]";
$mooninfo = str_replace($mooninfo, "", $tide[0]);
if (strstr($mooninfo, "First Quarter Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moon1stQ.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "Last Quarter Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonlastQ.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "Full Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonfull.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "New Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonnew.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}
}
//
// Check whether we are using Rising & Falling format
if ($risingFormat == "yes")
{
// Adjust Rising Falling Format for 3 tide days and 4 tide days
if (strstr($tide[10], $days))
{
$tides = $tide[0]."|".$tide[1]."|".$tide[2]."|".$tide[3]."|".$tide[4]."|".$tide[5]."|".$tide[6]."|".$tide[7];
}else{
$tides = $tide[0]."|".$tide[1]."|".$tide[2]."|".$tide[3]."|".$tide[4]."|".$tide[5]."|".$tide[6]."|".$tide[7]."|".$tide[8];
}
$tide = explode("|", $tides);
//
// Convert Rising Falling format to standard if set in options
if ($convertRF == "yes")
{
if (strstr($tide[1], "Rising") Xor (strstr($tide[1], "Falling")))
{
$tides = "<b>".$dformat." ".$moonimage."</b><br>".str_replace($tideWords, $translate, $tide[2])."<br>".str_replace($tideWords, $translate, $tide[4])."<br>".str_replace($tideWords, $translate, $tide[6])."<br>".str_replace($tideWords, $translate, $tide[8]);
}else{
// if it's not in row 1 it's in row 2
$tides = "<b>".$dformat." ".$moonimage."</b><br>".str_replace($tideWords, $translate, $tide[1])."<br>".str_replace($tideWords, $translate, $tide[3])."<br>".str_replace($tideWords, $translate, $tide[5])."<br>".str_replace($tideWords, $translate, $tide[7]);
}
}else{
$tides = "<b>".$dformat." ".$moonimage."</b><br>".str_replace($tideWords, $translate, $tide[1])."<br>".str_replace($tideWords, $translate, $tide[2])."<br>".str_replace($tideWords, $translate, $tide[3])."<br>".str_replace($tideWords, $translate, $tide[4])."<br>".str_replace($tideWords, $translate, $tide[5])."<br>".str_replace($tideWords, $translate, $tide[6])."<br>".str_replace($tideWords, $translate, $tide[7])."<br>".str_replace($tideWords, $translate, $tide[8])."<br>".str_replace($tideWords, $translate, $tide[9]);
}
}else{
// Working with regular High & Low format
// Adjust regular format for 2 tide days, 3 tide days and 4 tide days
if (strstr($tide[3], date("m-d", $time+(86400*($numb+1)))))
{
$tides = $tide[0]."|".$tide[1];
}else if (strstr($tide[4], date("m-d", $time+(86400*($numb+1)))))
{
$tides = $tide[0]."|".$tide[1]."|".$tide[2];
}else{
$tides = $tide[0]."|".$tide[1]."|".$tide[2]."|".$tide[3]."|".$tide[4];
}
$tide = explode("|", $tides);
$tides = "<b>".$dformat." ".$moonimage."</b><br>".str_replace($tideWords, $translate, $tide[1])."<br>".str_replace($tideWords, $translate, $tide[2])."<br>".str_replace($tideWords, $translate, $tide[3])."<br>".str_replace($tideWords, $translate, $tide[4]);
}
if (strlen($tides) < 50)
{
echo "";
}else{
if ($echoOff == "1")
{
return $tides;
}else{
echo $tides;
}
}
}
//
//
// Sun & Moon rise & set function
function sunmoon($numb = 0, $showDate = "yes", $echoOff = 0)
{
global $tidefile;
global $moonimg;
global $yearDate;
global $SmoonPhaseOff;
global $translate;
global $months;
global $transDay;
// Get tide file
error_reporting(0);
$tideD = implode('', file($tidefile));
if ($tideD == false)
{
// If there is no data we assume the tide file is currently being uploaded!
echo "<font color = \"red\">Data is being updated. Please refresh the page.</font>";
}
// Time & default words
$time = time();
$days = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
$tideWords = array("High Tide", "Low Tide", "Rising", "Falling", "Sunrise", "Sunset", "Moonrise", "Moonset");
//
// Get tide records by date, cut to length and split
// If year is included in date
if ($yearDate == "yes")
{
$tidedate = strstr($tideD, date("l Y-m-d", $time+(86400*$numb)));
$tideEnd = strpos($tideD, date("l Y-m-d", $time+(86400*($numb+1))));
}else{
$tidedate = strstr($tideD, date("l m-d", $time+(86400*$numb)));
$tideEnd = strpos($tideD, date("l m-d", $time+(86400*($numb+1))));
}
// The last tide will not show because it is not followed by a date. So we will
// set the end possition to a fixed leangth
if (!$tideEnd == false)
{
$tide = substr($tidedate, 0, $tideEnd);
}else{
$tide = substr($tidedate, 0, 280);
}
$tide = explode("\n", $tide);
// Convert date format to short day and full month names (UK format)
if ($yearDate == "yes")
{
$tideraw1 = $tide[0];
$dateraw = str_replace(" ","-", $tideraw1);
$dateraw = explode("-", $dateraw);
// Fix missing months on month numbers preseded by 0 with years in date
if (strlen($dateraw[2]) == 2 && substr($dateraw[2],0,1) == 0)
{
$dateraw[1] = substr($dateraw[2],1,1);
}
$daterawM = $months[$dateraw[2]];
}else{
$tideraw1 = $tide[0];
$dateraw = str_replace(" ","-", $tideraw1);
$dateraw = explode("-", $dateraw);
// Fix missing months on month numbers preseded by 0
if (strlen($dateraw[1]) == 2 && substr($dateraw[1],0,1) == 0)
{
$dateraw[1] = substr($dateraw[1],1,1);
}
$daterawM = $months[$dateraw[1]];
}
// translate days
$Day =str_replace($days, $transDay, $dateraw[0]);
if ($yearDate == "yes")
{
$dformat = substr($Day,0,3)." ".$dateraw[3]." ".$daterawM;
}else{
$dformat = substr($Day,0,3)." ".$dateraw[2]." ".$daterawM;
}
// Get moon details and show icons
if ($SmoonPhaseOff !== "yes")
{
$mooninfo= "$dateraw[0] $dateraw[1]-$dateraw[2]";
$mooninfo = str_replace($mooninfo, "", $tide[0]);
if (strstr($mooninfo, "First Quarter Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moon1stQ.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "Last Quarter Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonlastQ.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "Full Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonfull.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}else if (strstr($mooninfo, "New Moon"))
{
$moonimage = "<img src=\"$moonimg/tide_moonnew.gif\" alt=\"$mooninfo\" width=\"12\" height=\"10\">";
}
}
// Final output
if ($showDate == "nodate")
{
$moonsun = str_replace($tideWords, $translate, $tide[1])."<br>".str_replace($tideWords, $translate, $tide[2]);
}else{
$moonsun = "<b>".$dformat." ".$moonimage."</b><br>".str_replace($tideWords, $translate, $tide[1])."<br>".str_replace($tideWords, $translate, $tide[2]);
}
if (strlen($moonsun) < 40)
{
echo "";
}else{
if ($echoOff == "1")
{
return $moonsun;
}else{
echo $moonsun;
}
}
}
//
//
function tidesv()
{
global $SCVersion;
echo "Tide script ".$SCVersion." by <a href=\"http://www.newtonandnoss.com/weather/\" target = \"_blank\">NewtonAndNoss.com</a>";
}
?>
That script opens a tide html file

Code: Select all

$tidefile = "http://www.tbyc.org/weather/tideprediction.html";
This can be replaced with a local file

File tideprediction.html

Code: Select all

<HTML><BODY><PRE>
<P><center><font size=+2>Local Tide predictions</P></Center></font>

Southend Pier, Thames Rvr
Sheerness, England - READ flaterco.com/pol.html
  + Corrections: High(-0:10 -0.50) Low(-0:02 -0.70)
Units are meters

Monday 2011-01-31   
Sunrise  7:37 AM GMTST, Sunset  4:43 PM GMTST
Moonrise  5:59 AM GMTST, Moonset  2:07 PM GMTST
   Low Tide:   4:20 AM GMTST   1.1
  High Tide:  10:21 AM GMTST   5.1
   Low Tide:   4:50 PM GMTST   1.1
  High Tide:  10:48 PM GMTST   5.1

Tuesday 2011-02-01   
Sunrise  7:36 AM GMTST, Sunset  4:45 PM GMTST
Moonrise  6:32 AM GMTST, Moonset  3:17 PM GMTST
   Low Tide:   5:21 AM GMTST   0.8
  High Tide:  11:15 AM GMTST   5.3
   Low Tide:   5:39 PM GMTST   1.0
  High Tide:  11:37 PM GMTST   5.3

Wednesday 2011-02-02   
Sunrise  7:34 AM GMTST, Sunset  4:47 PM GMTST
Moonrise  6:58 AM GMTST, Moonset  4:28 PM GMTST
   Low Tide:   6:08 AM GMTST   0.6
  High Tide:  12:02 PM GMTST   5.4
   Low Tide:   6:18 PM GMTST   0.9

Thursday 2011-02-03   New Moon
Sunrise  7:32 AM GMTST, Sunset  4:49 PM GMTST
Moonrise  7:20 AM GMTST, Moonset  5:37 PM GMTST
  High Tide:  12:18 AM GMTST   5.4
   Low Tide:   6:47 AM GMTST   0.5
  High Tide:  12:42 PM GMTST   5.4
   Low Tide:   6:51 PM GMTST   0.9

Friday 2011-02-04   
Sunrise  7:31 AM GMTST, Sunset  4:51 PM GMTST
Moonrise  7:38 AM GMTST, Moonset  6:46 PM GMTST
  High Tide:  12:54 AM GMTST   5.4
   Low Tide:   7:22 AM GMTST   0.4
  High Tide:   1:18 PM GMTST   5.4
   Low Tide:   7:22 PM GMTST   0.8

Saturday 2011-02-05   
Sunrise  7:29 AM GMTST, Sunset  4:53 PM GMTST
Moonrise  7:54 AM GMTST, Moonset  7:54 PM GMTST
  High Tide:   1:26 AM GMTST   5.4
   Low Tide:   7:55 AM GMTST   0.4
  High Tide:   1:51 PM GMTST   5.4
   Low Tide:   7:54 PM GMTST   0.7

Sunday 2011-02-06   
Sunrise  7:28 AM GMTST, Sunset  4:54 PM GMTST
Moonrise  8:09 AM GMTST, Moonset  9:00 PM GMTST
  High Tide:   1:55 AM GMTST   5.5
   Low Tide:   8:28 AM GMTST   0.4
  High Tide:   2:23 PM GMTST   5.4
   Low Tide:   8:26 PM GMTST   0.7

Monday 2011-02-07   
Sunrise  7:26 AM GMTST, Sunset  4:56 PM GMTST
Moonrise  8:24 AM GMTST, Moonset 10:07 PM GMTST
  High Tide:   2:25 AM GMTST   5.5
   Low Tide:   8:59 AM GMTST   0.5
  High Tide:   2:54 PM GMTST   5.3
   Low Tide:   8:56 PM GMTST   0.8

Tuesday 2011-02-08   
Sunrise  7:24 AM GMTST, Sunset  4:58 PM GMTST
Moonrise  8:41 AM GMTST, Moonset 11:14 PM GMTST
  High Tide:   2:56 AM GMTST   5.4
   Low Tide:   9:25 AM GMTST   0.6
  High Tide:   3:25 PM GMTST   5.2
   Low Tide:   9:23 PM GMTST   0.9

Wednesday 2011-02-09   
Sunrise  7:22 AM GMTST, Sunset  5:00 PM GMTST
Moonrise  9:00 AM GMTST, Moonset 12:22 AM GMTST
  High Tide:   3:28 AM GMTST   5.3
   Low Tide:   9:47 AM GMTST   0.8
  High Tide:   3:58 PM GMTST   5.1
   Low Tide:   9:49 PM GMTST   1.0

Thursday 2011-02-10   
Sunrise  7:20 AM GMTST, Sunset  5:02 PM GMTST
Moonset 12:22 AM GMTST, Moonrise  9:24 AM GMTST
  High Tide:   4:03 AM GMTST   5.2
   Low Tide:  10:09 AM GMTST   0.9
  High Tide:   4:34 PM GMTST   4.9
   Low Tide:  10:21 PM GMTST   1.1

Friday 2011-02-11   First Quarter Moon
Sunrise  7:19 AM GMTST, Sunset  5:04 PM GMTST
Moonset  1:30 AM GMTST, Moonrise  9:54 AM GMTST
  High Tide:   4:45 AM GMTST   5.0
   Low Tide:  10:45 AM GMTST   1.1
  High Tide:   5:19 PM GMTST   4.7
   Low Tide:  11:10 PM GMTST   1.3

Saturday 2011-02-12   
Sunrise  7:17 AM GMTST, Sunset  5:05 PM GMTST
Moonset  2:36 AM GMTST, Moonrise 10:33 AM GMTST
  High Tide:   5:37 AM GMTST   4.8
   Low Tide:  11:45 AM GMTST   1.3
  High Tide:   6:15 PM GMTST   4.6

Sunday 2011-02-13   
Sunrise  7:15 AM GMTST, Sunset  5:07 PM GMTST
Moonset  3:37 AM GMTST, Moonrise 11:24 AM GMTST
   Low Tide:  12:23 AM GMTST   1.4
  High Tide:   6:47 AM GMTST   4.6
   Low Tide:   1:05 PM GMTST   1.4
  High Tide:   7:33 PM GMTST   4.5

Monday 2011-02-14   
Sunrise  7:13 AM GMTST, Sunset  5:09 PM GMTST
Moonset  4:30 AM GMTST, Moonrise 12:28 PM GMTST
   Low Tide:   1:51 AM GMTST   1.5
  High Tide:   8:22 AM GMTST   4.6
   Low Tide:   2:30 PM GMTST   1.4
  High Tide:   9:03 PM GMTST   4.6

Tuesday 2011-02-15   
Sunrise  7:11 AM GMTST, Sunset  5:11 PM GMTST
Moonset  5:14 AM GMTST, Moonrise  1:43 PM GMTST
   Low Tide:   3:22 AM GMTST   1.3
  High Tide:   9:43 AM GMTST   4.9
   Low Tide:   3:51 PM GMTST   1.2
  High Tide:  10:10 PM GMTST   5.0

Wednesday 2011-02-16   
Sunrise  7:09 AM GMTST, Sunset  5:13 PM GMTST
Moonset  5:49 AM GMTST, Moonrise  3:06 PM GMTST
   Low Tide:   4:40 AM GMTST   0.9
  High Tide:  10:43 AM GMTST   5.3
   Low Tide:   4:56 PM GMTST   0.9
  High Tide:  11:03 PM GMTST   5.3

Thursday 2011-02-17   
Sunrise  7:07 AM GMTST, Sunset  5:14 PM GMTST
Moonset  6:17 AM GMTST, Moonrise  4:32 PM GMTST
   Low Tide:   5:36 AM GMTST   0.5
  High Tide:  11:33 AM GMTST   5.6
   Low Tide:   5:47 PM GMTST   0.7
  High Tide:  11:51 PM GMTST   5.6

Friday 2011-02-18   Full Moon
Sunrise  7:06 AM GMTST, Sunset  5:16 PM GMTST
Moonset  6:41 AM GMTST, Moonrise  5:59 PM GMTST
   Low Tide:   6:24 AM GMTST   0.3
  High Tide:  12:20 PM GMTST   5.8
   Low Tide:   6:33 PM GMTST   0.5

Saturday 2011-02-19   
Sunrise  7:04 AM GMTST, Sunset  5:18 PM GMTST
Moonset  7:02 AM GMTST, Moonrise  7:26 PM GMTST
  High Tide:  12:35 AM GMTST   5.8
   Low Tide:   7:09 AM GMTST   0.1
  High Tide:   1:06 PM GMTST   5.9
   Low Tide:   7:18 PM GMTST   0.4

Sunday 2011-02-20   
Sunrise  7:02 AM GMTST, Sunset  5:20 PM GMTST
Moonset  7:23 AM GMTST, Moonrise  8:53 PM GMTST
  High Tide:   1:19 AM GMTST   5.9
   Low Tide:   7:53 AM GMTST  -0.0
  High Tide:   1:50 PM GMTST   6.0
   Low Tide:   8:02 PM GMTST   0.3




</PRE></BODY></HTML>

If you could try running the todaytide.php from within your browser and see if get results. And then try it in your custom page and see if you get the same results?

I would appreciate that, just so I know its not a problem my end only

Cheers
skafreak
Registered User
Posts: 23
Joined: Sun Feb 22, 2004 3:00 pm

Re: Custom Page With PHP In It.

Post by skafreak »

It appears that the globals are not making it through into your functions for some reason. I don't use functions to often (more of an if/else) guy for all my scripts, so I'm not sure why they wouldn't be working. I removed the function tag from the page and everything should up within the phpbb custom page.
crazydiamond
Registered User
Posts: 23
Joined: Mon Jan 31, 2011 12:43 am

Re: Custom Page With PHP In It.

Post by crazydiamond »

Hours of playing around I have figured out a way to do what I wanted.

Found a much much simpler way to do this.

In the HTML file I added

Code: Select all

<iframe src="http://www.tbyc.org/weather/index.php" width="660" height="649"  frameborder="0"scrolling="no"> Your browser does not support iframes.</iframe>
Also works with the local php files on my server

Code: Select all

<iframe src="todaytide.php" width="150" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
Loads a php file within a custom php page.Exactly what I wanted it to do.

I hope this post will save someone else the time it has taken me to work this out :mrgreen:

Thanks all
gabbariele
Registered User
Posts: 9
Joined: Wed Sep 15, 2010 9:12 am

Re: Custom Page With PHP In It.

Post by gabbariele »

Hi all, I have the same kind of trouble, I guess.
Really my custom phpbb pages work very well, since I try to put in them, some specific php code, for example to write inside a database, or well, I guess that's the problem.
If I'm out of the phpbb session, the code works perfectly.
If I'm in the phpbb session, the code works, writing datas into the database correclty, but I get an error and nothing is displayed on the webpage, but this:

Code: Select all

This webpage is not available
La pagina web all'indirizzo http://www.furians.it/MERLO-aggiorna_database.php potrebbe essere temporaneamente non disponibile oppure è stata permanentemente spostata a un nuovo indirizzo web.
Errore 330 (net::ERR_CONTENT_DECODING_FAILED): Errore sconosciuto.
That's italian and means simply that the webpage could be moved or temporary not avaible. Error 330: unknown error.

Correctly, I should see a page writing something like: "Ok everything is done".
The page works perfectly, if I delete the phpbb session part of the code. But I need it :(

Maybe there are some php codes that force phpbb to "lock" the page to the browser? Php is enabled in ACP, BTW.
crazydiamond
Registered User
Posts: 23
Joined: Mon Jan 31, 2011 12:43 am

Re: Custom Page With PHP In It.

Post by crazydiamond »

Hi, can you not try and solve this the way I have?

Create your custom page and edit the HTML file to open your php script

Code: Select all

<iframe src="yourPHPfile.php" >
<p>Your browser does not support iframes.</p>
</iframe>
Works for me for local and remote php pages
gabbariele
Registered User
Posts: 9
Joined: Wed Sep 15, 2010 9:12 am

Re: Custom Page With PHP In It.

Post by gabbariele »

crazydiamond wrote:Hi, can you not try and solve this the way I have?

Create your custom page and edit the HTML file to open your php script

Code: Select all

<iframe src="yourPHPfile.php" >
<p>Your browser does not support iframes.</p>
</iframe>
Works for me for local and remote php pages
I can try, but first I need to understand what is this iframe, and where to put it. Because I'm not including a template in a new phpbb page, but I'm just opening the php session in a php page.
crazydiamond
Registered User
Posts: 23
Joined: Mon Jan 31, 2011 12:43 am

Re: Custom Page With PHP In It.

Post by crazydiamond »

I don't know if what you are trying to achieve is the same as what I was trying to achieve.
But I would suggest you try the method that worked for me, even to rule it out.

I made a custom page with this guide
http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/

In the php custom file there is a line of code that points to the HTML file that will contain your code.

Code: Select all

'body' => 'yourpage_body.html',     
yourpage_body.html

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>Title Here</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
         Content in here. 
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
Where is asks for your code
Content in here.
I just put

Code: Select all

<iframe src="yourPHPfile.php" >
<p>Your browser does not support iframes.</p>
</iframe>
This inserts your php file inside the body of the 1st php file you made via the HTML code.
Works for me and I can finally display or run the code.

Make sure you Purge the cache and refresh your template.
Also that php inside templates is enabled (Although that might not matter in my case)

Hope I have been of some help
gabbariele
Registered User
Posts: 9
Joined: Wed Sep 15, 2010 9:12 am

Re: Custom Page With PHP In It.

Post by gabbariele »

I'm not including a template html page in a new phpbb page.
I'm opening the phpbb session direclty in the page I want to show, like this:

Code: Select all

//this is to keep variables from the first page
<?php
//Apro la sessione
session_start();
$_SESSION['snew_nomepg'] = $_POST['nomepg'];
$_SESSION['snew_razza'] = $_POST['razza'];
$_SESSION['snew_classe'] = $_POST['classe'];
$_SESSION['snew_rank'] = $_POST['rank'];
$_SESSION['snew_livello'] = $_POST['livello'];
$_SESSION['snew_job'] = $_POST['job'];
$_SESSION['snew_job2'] = $_POST['classleader'];
$_SESSION['snew_crafting'] = $_POST['crafting'];
?>

//this is to open the phpbb session
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './phpbb/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['group_id'] == 1 || $user->data['user_id'] == ANONYMOUS || $user->data['group_id'] == 7 || $user->data['group_id'] == 2 || $user->data['group_id'] == 3 || $user->data['group_id'] == 6 || $user->data['group_id'] == 14 || $user->data['group_id'] == 15)
{
   login_box('', $user->lang['LOGIN']);
} 

//I need to use this variable
global $user;
$name=$user->data['username']; 
?>

<body>
//inside the body, there is this code:
<?
//connection to the db
require "connection.php";
//retriving session variables from the session
$new_nomepg = $_SESSION['snew_nomepg'];
$new_razza = $_SESSION['snew_razza'];
$new_classe = $_SESSION['snew_classe'];
$new_rank = $_SESSION['snew_rank'];
$new_livello = $_SESSION['snew_livello'];
$new_job = $_SESSION['snew_job'];
$new_job2 = $_SESSION['snew_job2'];
$new_crafting = $_SESSION['snew_crafting'];

mysql_db_query($db_database,"insert into ".$db_tabella."(nomepg, razza, classe, rank, livello, job, classleader, crafting, nome_utente) values('".$new_nomepg."', '".$new_razza."', '".$new_classe."', '".$new_rank."', '".$new_livello."', '".$new_job."', '".$new_job2."', '".$new_crafting."', '".$name."')",$con);

?>
</body>
Basicly I need to write datas into mysql database. Everythng is written, but the page doesn' show itself. If I delete the phpbb session code, everithing works perfeclty, but I cannot use the global variable $name that I need soooooo much :)
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53538
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Custom Page With PHP In It.

Post by Brf »

You need to execute the phpBB session code before you send any HTML output.
You have a blank line and two comment lines being sent before the phpBB session code.

Note that $user is already global. Since this is a top-level script, not a function, you do not need to declare it global again.
gabbariele
Registered User
Posts: 9
Joined: Wed Sep 15, 2010 9:12 am

Re: Custom Page With PHP In It.

Post by gabbariele »

Brf wrote:You need to execute the phpBB session code before you send any HTML output.
You have a blank line and two comment lines being sent before the phpBB session code.

Note that $user is already global. Since this is a top-level script, not a function, you do not need to declare it global again.
Thanks, really the blank line and the comment are only here :) In the page code the phpbb session starts just after the other session. Corrected the variable issue, but still the same problem.

Code: Select all

<?php
//Apro la sessione
session_start();
$_SESSION['snew_nomepg'] = $_POST['nomepg'];
$_SESSION['snew_razza'] = $_POST['razza'];
$_SESSION['snew_classe'] = $_POST['classe'];
$_SESSION['snew_rank'] = $_POST['rank'];
$_SESSION['snew_livello'] = $_POST['livello'];
$_SESSION['snew_job'] = $_POST['job'];
$_SESSION['snew_job2'] = $_POST['classleader'];
$_SESSION['snew_crafting'] = $_POST['crafting'];
?>
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './phpbb/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
if ($user->data['group_id'] == 1 || $user->data['user_id'] == ANONYMOUS || $user->data['group_id'] == 7 || $user->data['group_id'] == 2 || $user->data['group_id'] == 3 || $user->data['group_id'] == 6 || $user->data['group_id'] == 14 || $user->data['group_id'] == 15)
{
   login_box('', $user->lang['LOGIN']);
} 

$name=$user->data['username'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<STYLE>
BODY {
	margin: 0px 0px 0px 0px;
	background-color: #000;
}
.a {	font-family: Arial, Helvetica, sans-serif;
	color: #FFF;
	font-size: 12px;
}

....and so on
edrimon
Registered User
Posts: 49
Joined: Tue Jul 15, 2014 12:20 pm

Re: Custom Page With PHP In It.

Post by edrimon »

@skafreak above: Thanks a lot! That was exactly what I was looking for and googled a lot for it!

Why there is no such documentation in phpbb website???

Thanks a lot again
edrimon
Registered User
Posts: 49
Joined: Tue Jul 15, 2014 12:20 pm

Re: Custom Page With PHP In It.

Post by edrimon »

skafreak wrote:OK, I got this working now.

First you must enable PHP use within your Admin Control Panel. (This was something I was missing before).
Second you setup your main php file that will go in the root directory, we will call this main.php. Then place this code in that file.

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Title Here');

$template->set_filenames(array(
    'body' => 'main_body.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
Change 'Title Here' to the title of the page and 'main_body.html' to the name of the template page that we will make next. So, now make main_body.html and place it in the styles/yourstyle/template/ folder. Then put this code in that file.

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>About Us</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
         We were founded this year to bring you the best forum on the Internet!
         
         We promise to do the following:
         <ul>
            <li>Provide new content</li>
            <li>provide a friendly atmosphere</li>
            <li>Provide an environment where you can have fun!</li>
         </ul>
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDEPHP main2.php -->
<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
You can adjust html and whatnot here. You also place

Code: Select all

<!--INCLUDEPHP main2.php -->
here
which points to your full php file. Create main2.php and place it in your root directory and add whatever php code you want.
Finally, login to your Admin Control Panel select the Styles tab, then Templates on the left, then refresh the template you are using.
That should do the trick.
Hi, I have now another question based on the above.
Normally main.php will work as the example above. But what happens if I want to pass some form POST or GET info in main2.php?

I mean if a have a form in another page, where the form action should point? If we use main.php it will not work as main2.php will be used to handle those variables. But from the other hand main.php and not main2.php is called..

So how to handle forms in this case? I just need a form to be able to make some SQL queries and display the output.

Thanks
_Elixir
Registered User
Posts: 10
Joined: Sun Oct 13, 2013 2:36 am

Re: Custom Page With PHP In It.

Post by _Elixir »

Sry for revive this, but this is topic i need . I want to add a custom php page . The solution with iframe, work, but it look so tiny, and i dont want in this way . I follow the other instructions with the includephp in the aboutus_html but it doesnt work . Also i try to put the php code in the aboutus.php , it work but all show above the template . Im running phpbb 3.0.12 . Some help, thx

Return to “[3.0.x] MOD Writers Discussion”