+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [PHP - TUT] Site Online/Offline Status

  1. #1
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    [PHP - TUT] Site Online/Offline Status

    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:

    PHP Code:
    // 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 Code:
    // 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 Code:
    // 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 Code:
    .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.
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  2. #2
    Grandcruiser is offline x10 Sophmore Grandcruiser is an unknown quantity at this point
    Join Date
    Jun 2007
    Posts
    155

    Re: [PHP - TUT] Site Online/Offline Status

    Sweet thanks...

  3. #3
    Derek is offline Community Support Force Derek is a splendid one to beholdDerek is a splendid one to behold
    Join Date
    May 2005
    Location
    cossacks
    Posts
    6,354

    Re: [PHP - TUT] Site Online/Offline Status

    Thanks.

  4. #4
    z0lik's Avatar
    z0lik is offline x10Hosting Member z0lik is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    Moldova
    Posts
    19

    Re: [PHP - TUT] Site Online/Offline Status

    Thanks Man!

    Please click me Pic's [^]
    ----------------------------------------------------------------------------------

    Please Donate me!
    Studing : html / php / asm / c++ :biggthump

  5. #5
    Despistado is offline x10Hosting Member Despistado is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    96

    Re: [PHP - TUT] Site Online/Offline Status

    wow you have a great knowledge with php, thats fantastic, this is very helpful thank you so much

    best regards

  6. #6
    Poyzin's Avatar
    Poyzin is offline x10Hosting Member Poyzin is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    3

    Re: [PHP - TUT] Site Online/Offline Status

    That is really great! :happysad: I needed this :-P.

  7. #7
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    Re: [PHP - TUT] Site Online/Offline Status

    Thanks for the feedback guys, hope you enjoy the script
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  8. #8
    Icecoldcoke is offline x10Hosting Member Icecoldcoke is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    60

    Re: [PHP - TUT] Site Online/Offline Status

    I get this
    "Parse error: syntax error, unexpected '&' in /index.php on line 7"

    It could be something with it making 5,000 "&nbsp" whenever I save them..

    EDIT: NM..

    But Im blocked from my website when it's down.. lol
    Last edited by Icecoldcoke; 10-27-2007 at 07:31 PM.

  9. #9
    Synkc's Avatar
    Synkc is offline Lord Of The Keys Synkc is an unknown quantity at this point
    Join Date
    Jun 2007
    Location
    Hervey Bay, Australia
    Posts
    1,765

    Re: [PHP - TUT] Site Online/Offline Status

    Did you change the "$admin_ip" variable in config.php to your IP address?
    E-mail: synkc[at]x10hosting[dot]com
    Hirokima.com

  10. #10
    Icecoldcoke is offline x10Hosting Member Icecoldcoke is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    60

    Re: [PHP - TUT] Site Online/Offline Status

    Quote Originally Posted by Synkc View Post
    Did you change the "$admin_ip" variable in config.php to your IP address?
    Yup

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. a site without frames and a site with frame
    By n4tec in forum Scripts & 3rd Party Apps
    Replies: 18
    Last Post: 12-31-2007, 02:20 PM
  2. Link Exchange
    By Conor in forum Scripts & 3rd Party Apps
    Replies: 117
    Last Post: 12-09-2007, 12:20 PM
  3. My site.. Need staff... maybe...
    By dsfreak in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 08-05-2005, 10:07 PM
  4. Add Scrolling message to the site status bar
    By wizeman in forum Tutorials
    Replies: 15
    Last Post: 08-02-2005, 03:49 PM
  5. New Site Design- Reward
    By NewFuture in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 07-26-2005, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers