Support Forums
[SMF] Basic Server-Side Includes (SSI) - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: [SMF] Basic Server-Side Includes (SSI) (/showthread.php?tid=11649)



[SMF] Basic Server-Side Includes (SSI) - Project Evolution - 08-30-2010

Hello, today im going to be going over a basic structure to a useful concept of integrating your SMF forum into other parts of your website. Lets start by creating a simple php page,
Code:
<html>

   <head>
      <title>My site - index</title>
   </head>

   <body>
      <?php

      ?>
   </body>

</html>

Now we have our layout of the php file with a simple title. Let me begin by explaining SMF's SSI functions. Every single one of SMF's custimizable functions can be found in a file called SSI.php in the root of the SMF package. Contained within this file is loads of functions that display recent posts, new members, news feeds, etc. You can find an example of these functions by going to a file called ssi_examples.php (and/or ssi_examples.shtml). This file is located in the same place as SSI.php, in the root of SMF's package. For example, lets say the URL to my forum is faggots.com/smf. To access this file I would simple go to, faggots.com/smf/ssi_examples.php.

In order to use these SSI functions, we will place a PHP require function in the file and call the SSI.php file like so,
Code:
<?php require("URL-TO-THE-SSI.PHP-FILE"); ?>
<html>

   <head>
      <title>My site - index</title>
   </head>

   <body>
      <?php

      ?>
   </body>

</html>

There are some key specific things im going to point out here. As you can see, I called the require() function above anything else in the file, why? Firstly, I use this as a personal habit to make sure I call this before trying to access anything from the file im trying to access. In my next SSI tutorial, I will explain why this should be a good habit to get into. For now, just make sure your calling the require() function before attempting to use any of SMF's SSI functions.

Using SSI is quite simplistic, you simple just call the functions assosciated with it.
Lets dig a little deeper than calling functions. Say for example we wanted a tab in a navigation bar to show up if we are an admin, or remove the tab entirely if we are not. Lets take a look,
Code:
<div id="navigation">
            <ul>
                <li><a href="/">Home</a></li>
                <li><a href="/smf/">Forum</a></li>
                <li><a href="index.php?action=products">Products</a></li>
                <li><a href="index.php?action=portfolio">Portfolio</a></li>
                <li><a href="about.php">About</a></li>
                <?php
                 global $context;
                 if ($context['allow_admin'])
                    echo '<li><a href="#">Admin Panel</a></li>'; ?>
           </ul>
        </div>

Basically, what we need to do here is check whether or not we are an admin. Firstly, we create php tags to indicate we are going to be using PHP. We call the $context variable from SSI.php, then we create an if statement checking against whether or not we are an admin. If true, we echo the HTML which includes the 'secret' admin tab. Dont forget to create that $context variable otherwise it wont work!

Here is a simple function that handles a login box,
Code:
function show_login() {
    global $context;
    if ($context['user']['is_guest']) { // Check whether or not user is a guest - if so, display a login box with some extra content
        echo '<p class="title">Login</p>
            <span class="center" style="color: #FFFFFF;">', ssi_login() ,'</span>
            <br />
            <a href="http://faggots.com/smf/index.php?action=reminder">Forgot your password?</a>';
    } else { // If not - display a logout button
        echo '<p class="title">Logout</p>
            <span class="center" style="color: #FFFFFF;">', ssi_logout() ,'</span>';
    }
}

For those without SMF but interested in these functions, please see,
http://www.simplemachines.org/community/ssi_examples.php

You can also visit the Function DB to see the functions within SSI.php,
http://support.simplemachines.org/function_db/index.php?action=view_file;id=66

Thanks for reading.


RE: [SMF] Basic Server-Side Includes (SSI) - Sam - 08-30-2010

Thanks for the share, I know the SMF currently offers files to integrate with Xoops and other CMS software.


RE: [SMF] Basic Server-Side Includes (SSI) - Project Evolution - 08-30-2010

(08-30-2010, 10:04 AM)Sam Wrote: Thanks for the share, I know the SMF currently offers files to integrate with Xoops and other CMS software.

Yes, it certainly is helpful. :p