Synkc
Active Member
- Messages
- 1,765
- Reaction score
- 0
- Points
- 36
Intro:
This is a simple script I wrote a while ago; it allows you to simple turn your entire site offline, or just specific pages. It also permits you to have access, while displaying a "Site is currently offline" message at the top of each page.
Note:
This code requires that you use a "config.php" file to store all your site's varibles, and a "global.php" file, which is linked to both your config file and site pages, for executing the php that appears globally on your site.
For example, your site's root directory may contain:
- index.php
- config.php
- global.php
or
- index.php
- inc/config.php
- inc/global.php
etc.
Procedure:
Ok, first, copy the following code into your config.php file:
Remember to place it within the <? ?> tags.
Now place this into your global.php file:
Now, place the following code at the top of every page that you want to be able to turn offline:
Also, while placing this code, put a "$notice" after the opening <body> tag on each page. This will determine where on the page the offline message will appear for the admin.
To change the title of your pages from whatever to "SITENAME - PAGENAME :: Offline", you need to change the html title tag for each page into "<title>$title$page_title</title>" (without quotation marks).
Now finally, if you have a style sheet, open it and place at the bottom (Change this to suit your site's style):
If all done correctly, you can now turn off your site via your config.php file; just change the varible "$offline" to true.
If you have any questions, feel free to ask.
100% written by me, Synkc.
This is a simple script I wrote a while ago; it allows you to simple turn your entire site offline, or just specific pages. It also permits you to have access, while displaying a "Site is currently offline" message at the top of each page.
Note:
This code requires that you use a "config.php" file to store all your site's varibles, and a "global.php" file, which is linked to both your config file and site pages, for executing the php that appears globally on your site.
For example, your site's root directory may contain:
- index.php
- config.php
- global.php
or
- index.php
- inc/config.php
- inc/global.php
etc.
Procedure:
Ok, first, copy the following code into your config.php file:
PHP:
// Site Online status (false=Online, true=Offline)
$offline = false;
$ip = $_SERVER['REMOTE_ADDR'];
// The IP address of the administrator (Change to your ip if site is not locally hosted)
$admin_ip = '127.0.0.1';
// Site Messages
$message_offline = "The $site_name website is currently offline due to maintenance. Please check back soon!";
$admin_message_offline = "Notice: The site is currently set to \"offline\".";
Remember to place it within the <? ?> tags.
Now place this into your global.php file:
PHP:
// Links to the config.php file (change the path to suit)
require_once $_SERVER['DOCUMENT_ROOT'] ."/inc/config.php";
if($page_name == "") {
$page_title = "";
}
else {
$page_title = " - $page_name";
}
// Checks to see if the website is set to "offline" through the "config.php" file, and if it is it displays a message. Also changes the page title to show "Offline".
if ($offline == true) {
if($page_name == "") {
$page_title = " :: Offline";
}
else {
$page_title = " - $page_name :: Offline";
}
if($ip == $admin_ip){
$notice = "
<center>
<table class='offline'>
<tr>
<td align='center'>
<strong>
$admin_message_offline
</strong>
</td>
</tr>
</table>
</center>";
}
else {
echo "$message_offline";
exit;
}
}
Now, place the following code at the top of every page that you want to be able to turn offline:
PHP:
// Links to the global.php file (change the path to suit)
require_once $_SERVER['DOCUMENT_ROOT'] .'/inc/global.php';
$page_name = "YOUR PAGE'S NAME";
Also, while placing this code, put a "$notice" after the opening <body> tag on each page. This will determine where on the page the offline message will appear for the admin.
To change the title of your pages from whatever to "SITENAME - PAGENAME :: Offline", you need to change the html title tag for each page into "<title>$title$page_title</title>" (without quotation marks).
Now finally, if you have a style sheet, open it and place at the bottom (Change this to suit your site's style):
HTML:
.offline {
margin: 0px;
padding: 0px;
background-color:#FFFFFF;
}
If all done correctly, you can now turn off your site via your config.php file; just change the varible "$offline" to true.
If you have any questions, feel free to ask.
100% written by me, Synkc.