Page 1 of 1

Embedding the Forum phpBB3 into an iFrame on my website

Posted: Fri Jun 01, 2018 10:55 pm
by alex4orly
I will start by saying, Thank-you Pablo...

I don't say it is the ONLY way to do this, nor the best... but this is the way I figured out, after a lot of trial and error, and it works. So, I thought maybe someone else here on the forum can benefit from it.

Firstly, I renamed the page called "viewtopic.php" to "showtopic.php" so that I can have control of the actions taken when a forum member clicks on the link in his email - for example:

http://beleuramyhome.org.au/phpBB3/view ... ead#unread

If you click on such a link in your email, it will take you to the relevant page, BUT - outside of your website...
My challenge was to embed it - within... and I used an iFrame for that

// In the replacement page - viewtopic.php at the top

Code: Select all

<?php
   session_start();
   
   // Get the URL passed into the page
   $uri    = $_SERVER['REQUEST_URI'];

   // I just need the URL arguments, so strip off the URL itself
   $str    = substr($uri, 22);  
 
   // Feed the arguments into a session variable
   // I tried using the $str, but didn't work for some reason
   $_SESSION['params'] = substr($uri, 22);
   
   // Prepare for a redirect to my website page - with the iFrame in it
   $newpage = "http://www.beleuramyhome.org.au/iframeurl.php?";

   // Add the URL arguments
   $newpage .= $str;
   
   // Use this to redirect, because the URL is an argument and can't 
   // be hard coded. That's why I couldn't use the header() function...
   echo '<META HTTP-EQUIV="Refresh" Content="2; URL='.$newpage.'">';   
?>
// In the target page - iframeurl.php, where the iFrame is, at the top of the page

Code: Select all

<?php
   session_start();
   
   // Get the URL passed in from the first step
   $uri    = $_SERVER['REQUEST_URI'];   
   // Strip the URL itself, I need only the arguments
   $_SESSION['params'] = substr($uri, 15);
?>
// In the same page, between the <head> section, I inserted this Javascript function

Code: Select all

<script>   
   
   // This function is called on page load
   window.onload = function()
   {
	  // I will redirect the content into the iFrame, pointing to the 
	  // new page created at the begining 
      var url = "http://beleuramyhome.org.au/phpBB3/showtopic.php?"; 
	  // Get the Session arguments
      var args = "<?php echo $_SESSION['params'] ?>";
	  // Add those to the URL
      url += args; 
      // The actual job of inserting it into the iFrame
      document.getElementById("InlineFrame1").setAttribute("src", url);
	  
	  // Try this URL to see how it works
	  // http://beleuramyhome.org.au/phpBB3/viewtopic.php?f=6&t=3&e=1&view=unread#unread
   }
</script>

Re: Embedding the Forum phpBB3 into an iFrame on my website

Posted: Fri Jun 01, 2018 11:13 pm
by BaconFries
Since this is a 'Tip' for others on how to achieve I have moved to the following: WYSIWYG Web Builder Tips, Tricks, Tutorials and Code Examples

Re: Embedding the Forum phpBB3 into an iFrame on my website

Posted: Fri Jun 01, 2018 11:14 pm
by alex4orly
Thank you,
I was looking for that forum and d it

Cheers

Re: Embedding the Forum phpBB3 into an iFrame on my website

Posted: Fri Jun 01, 2018 11:16 pm
by BaconFries
Thanks for sharing this Alex. I think others will find it useful... it might even be possible to skin it with a simliar colour theme to there own sites so that it blends nicely.

Re: Embedding the Forum phpBB3 into an iFrame on my website

Posted: Sat Jun 02, 2018 6:47 am
by Pablo
Thanks for sharing your solution!