2011-01-13, 10:53 AM
Well, this might make plugin developers faint, but here's what I'm doing:
I'm an absolute beginner in PHP and today I've written (highly based on tutorials) a login script. It allows me to add a little PHP script at the top of my pages to check whether the user is logged in or not. If he's not, it will redirect him to the login page. I need this script to run on a MyBB forum I have made up for the website of my charity association. I don't want to use any plugin as I want this very special script to run. I won't bother you with details.
So basically I have added the checking script in head_include. No errors are showing up (this is good at least) but even if I'm not loged in, it doesn't prompt the login page. The code is perfectly working, I've wrote in on some test html/php pages before trying to add into MyBB.
So, I guess header_include isn't the good place to add this script. Or MyBB is blocking the execution of this script this it's not an installed plugin (I don't know how to make it into a plugin, so as I've already done enough PHP for a first day, I'd like to avoid turning it into a plugin).
Maybe I'm all wrong, and.. I don't know. I know my script it working, and if it could run at the beginning of each page of my forum, it would be perfect. Here's the script I'd like to run:
Thanks guys, and sorry if I'm not clear.
EDIT: Sorry, added the wrong PHP script. Also, another thing I'm not sure about, is whether I need to add the "<?php" "?>" bit, or is it not necessary?
I'm an absolute beginner in PHP and today I've written (highly based on tutorials) a login script. It allows me to add a little PHP script at the top of my pages to check whether the user is logged in or not. If he's not, it will redirect him to the login page. I need this script to run on a MyBB forum I have made up for the website of my charity association. I don't want to use any plugin as I want this very special script to run. I won't bother you with details.
So basically I have added the checking script in head_include. No errors are showing up (this is good at least) but even if I'm not loged in, it doesn't prompt the login page. The code is perfectly working, I've wrote in on some test html/php pages before trying to add into MyBB.
So, I guess header_include isn't the good place to add this script. Or MyBB is blocking the execution of this script this it's not an installed plugin (I don't know how to make it into a plugin, so as I've already done enough PHP for a first day, I'd like to avoid turning it into a plugin).
Maybe I'm all wrong, and.. I don't know. I know my script it working, and if it could run at the beginning of each page of my forum, it would be perfect. Here's the script I'd like to run:
<?php
session_start(); //It starts the session.
require_once("includes/connection.php");
include_once("includes/constants.php");
require_once("includes/functions.php");
is_logged_in();
?>
Thanks guys, and sorry if I'm not clear.
EDIT: Sorry, added the wrong PHP script. Also, another thing I'm not sure about, is whether I need to add the "<?php" "?>" bit, or is it not necessary?