SSI FAQ Basic

From Online Manual

Jump to: navigation, search

Basic SSI FAQ

Hello and welcome to the Basic SSI FAQ. In this FAQ, you will learn the basics of whats SSI, whether it can be used to your needs and how. This FAQ has commonly asked SSI questions as well as tips and tricks.

PLEASE DO NOT EDIT YOUR 'SSI.PHP' FILE Everything done here is done without having to edit 'SSI.php'

What's SSI?

SSI - Server Side Includes, is a feature we use to help link our community board to the rest of our site, it also helps us take forum stats, news, announcements, recent posts...etc and view those things on other pages in our site.


How Can SSI Help me?

Even you can find use with SSI, lets take an example:

Example:

You have a site, and also a forum, and you want logged in members to see a special downloads area on the downloads screen.

For something like this, SSI is needed and can be created in minutes


Fine SSI is good, how do I start using it?

The first thing you need to do is open a new file somewhere in your site, and give it a .php extention. Then open your text editer for that file and write this code:


<?php
require("/home/simple/public_html/forum/SSI.php"); 
?>

But make sure the path is the correct path for you to the 'SSI.php' file located in your forum directory, to see [b]YOUR[/b] correct path, check out the top part of 'ssi_examples.php' file located in your forum directory.


Ok I got the correct path to 'SSI.php', whats next?

Ok if you have got your correct path to SSI.php and written it in the file you created in the format I showed above, then good job. Next we will try to add features to your page [eg. menu bar, who's online list...etc]. Try this code between the 'require...' statement and the '?>' code


ssi_menubar();

Now try going to your page in your browser, if everything went well, you should see your menu bar from your forum, if you dont see anything there or some error message, that is probaly because you didnt write that correct path to your 'SSI.php' file. Well now that you got this working, you can go have fun with it, you can add many functions to your page, all the functions are listed in the 'ssi_examples.php' file located in your forum directory. [Also your correct 'SSI.php' path is listed in that file at the top]


That was cool, any more?

Yes, there is more to SSI than the functions. Now, I will show you how the user permissions work by showing you how to write this example:

Example:

You have a site, and also a forum, and you want logged in members to see a special downloads area on the downloads screen. This is easy stuff to do, and I will show you how using PHP's 'if' statement:


<?php
require("YOUR_PATH_TO_SSI.php"); 

if ($context['user']['is_guest'])
 {
   echo 
   '<h5>Access Denied</h5>
   We are sorry guest, it seems you dont have permission to view these downloads.';
 }
else
 {
   echo
   '<h5>Welcome ', $context['user']['name'], '!</h5>
   Here are your downloads:';
 }
?>

I will explain the script I have written above: The 'if' statements works on true and flase, if the statement [In our case: ($context['user']['is_guest'])] is true, the first block is activated, and if false, the 'else' block is activated. So in our case, if you aren't logged in [You are a guest] you will see an access denied message, and if you are logged in, you will see the downloads area. You can use that in any way you wish.

You can do the same thing but with admin


if ($context['allow_admin'])
  {
   Block of statements
  }
else
  {
   Block of statements
  }


Well this pretty much covers the basic Guide, the next guide is: 'Advanced SSI FAQ'.

Attached to the end of [this post] are some sample scripts that may help you out.

  • membergroup.txt Put's your membergroup in a variable for later use.
  • welcome.txt If your a guest, shows a login box, if not, a welcome message.

Copied from http://www.simplemachines.org/community/index.php?topic=12936.0