Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 4 1234 LastLast
Results 1 to 10 of 36
  1. #1
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default [PHP] Maintenance Panel Tutorial

    If you need to turn your site on and off quickly, then I think I might've helped you out.

    This tutorial will teach you how to make a PHP/MySQL site status editor with a login page.

    Got moved into Tutorials section after being out for 2 minutes!

    Requirements:
    - A PHP Server
    - A MySQL Database
    - A Notepad or FTP Client
    - A little HTML knowledge for styling. (Optional)

    Note:
    If you don't understand the code, then read the comments in it, they're there for a reason, to help you!

    Step 1:
    The Database
    Create a new MySQL database, call it whatever you wish but something appropriate like "status" etc would be best.
    Keep your database information with you, you will need it in Part 2.
    Run the following MySQL query:
    PHP Code:
     CREATE TABLE `sitestatus` (
    `
    idINTNOT NULL AUTO_INCREMENT ,
    `
    statusVARCHAR10 NOT NULL ,
    `
    offmsgTEXT NOT NULL ,
    `
    onpageVARCHAR50 NOT NULL ,
    PRIMARY KEY ( `id` )
    ENGINE MYISAM 

    INSERT INTO 
    `sitestatus` (
    `
    id` ,
    `
    status` ,
    `
    offmsg` ,
    `
    onpage`
    )
    VALUES (
    '1''off''The site is currently offline for some much needed maintenance work on the frameworks!''http://example.com/'
    ); 
    You have now set up your database.
    End of Step 1

    Step 2:
    The General Configuration
    Create a new .php document, call it config.php, in the file, add the following code:
    PHP Code:
    <?php
    //==============================================================================
    $host "localhost";     //Set this to the database host.
    $user "root";          //Set this to the database username.
    $pass "";              //Set this to the database password.
    $name "users";         //Set this to the database name.
    $set_password "12321"//Set this to the password you want the user to provide before they're given access to the site.
    //==============================================================================
    mysql_connect($host,$user,$pass); //Connects to the database.
    mysql_select_db($name); //Selects the database.
    $info mysql_query("SELECT * FROM `sitestatus` WHERE `id` = '1' ;"); //Is getting the information we need.
    $i mysql_fetch_object($info); //Is formatting the information we need.
    ?>
    Read the comments, then the code will all make sence.
    Now, you need to edit the database connection info at the top of the script, you should already know this from when you set up the database in Part 1.
    End of Step 2

    Step 3:
    The Login & Information Editor
    Create yet another .php document, this time calling it login.php, in the file, add the following code:
    PHP Code:
    <?php
    require("config.php"); //Includes the configuration file we made earlier. 
    if(!isset($_POST['login'])){ //If they haven't posted the login form...
        
    echo("Please enter the password to edit the site status!<br />
        <form method=\"post\">
        Password: <input type=\"password\" name=\"password\">
        <br />
        <input type=\"submit\" value=\"Login\" name=\"login\">
        </form>"
    );
        
    //^^ Then show the login form so they can login.
    }else{ //If they have posted the login form...
        
    $s_password $_POST['password']; //Change the password variable to something easier to handle.
        
    if($s_password != $set_password){ //If the supplied password doens't match the set password in the configuration file...
            
    die("You did not enter the correct password!"); //Tell them so, and close the session so they can't edit anything.
        
    //Ends the if statement (the supplied password didn't match the set one)
        
    setcookie("loggedin","yes"); //Sets a cookie with the users information in, will be used in the next step.
        
    header("Location: edit.php"); //Sends them off to the edit info page.
    //End the if statement (the login from hasn't been posted)
    mysql_close(); //Close any remaining MySQL connections.
    ?>
    You shouldn't need to edit this code too much.
    Now, moving onto the information editor page, create another .php document, this one called edit.php, in the file, add the following code:
    PHP Code:
    <?php
    require("config.php"); //Includes the configuration file.
    if($_COOKIE[loggedin] == "yes"){ //If they're logged in...
            
    if(!isset($_POST['update'])){ //Check to see if they've posted the form yet.
                
    echo("Please choose the setting to edit here:<br />
                <form method=\"post\">
                Site Status: <select name=\"status\"><option value=\"on\">On</option><option value=\"off\">Off</option></select>
                <br />
                Offline Message: <input type=\"text\" name=\"offmsg\" size=\"40\">
                <br />
                Online Page To Redirect To: <input type=\"text\" name=\"onpage\" size=\"30\">
                <br />
                <input type=\"submit\" value=\"Update!\" name=\"update\">
                </form>"
    );
                
    //^^ Show them the form because they haven't posted it yet.
            
    }else{ //If they have posted the form...
                
    $status $_POST['status']; //Makes the variable easier to handle.
                
    $offmsg $_POST['offmsg']; //Makes the variable easier to handle.
                
    $onpage $_POST['onpage']; //Makes the variable easier to handle.
                
    mysql_query("UPDATE `sitestatus` SET `status` = '" $status "', `offmsg` = '" $offmsg "', `onpage` = '" $onpage "' ;"); //Updates the MySQL database with the information they specified in the form.
                
    echo("The site has been succesfully updated!"); //Tells them that the database has been updated.
                 
    setcookie("loggedin","",time() - 3600); //Unsets the logged in cookie.
             
    //End the if statement (if have(n't) posted the form yet.
    }else{ //If they're not logged in...
        
    die("Please login to edit the site status!"); //End the if statement(if they're (not) logged in.
    //End the if statment (if not logged in)
    mysql_close(); //Closes any remaining MySQL connections.
    ?>
    You shouldn't need to edit this code too much either.
    End of Part 3.

    Part 4:
    The Index page
    Create the final .php document, this one called index.php, it will replace the your current index, which you should rename to index2.php so you can make this script redirect to it when you've finished.
    On the page, add the following code:
    PHP Code:
    <?php
    require("config.php"); //Includes the configuration file we made earlier.
    if($i->status == "on"){ //If the site status is set to on...
        
    header($i->onpage); //Then forward the user to the online page.
    }elseif($i->status == "off"){ //If the site status is set to off...
        
    echo("The site is currently in offline mode!<br />The reason for this is: <b>" $i->offmsg "</b><br />We appologise for any disturbance this may cause.");
        
    //^^ Then tell them so, and show the offline message.
    //Closes the statement.
    mysql_close(); //Stops any MySQL connections we had running.
    ?>
    You shouldn't need to edit this code much, unless you want to change the phrasing on the offline page.
    End of Part 4.

    Now you should have completed my tutorial, I hope you have learnt something from it!
    If you have any comments to make, then please make them below.

    Thanks alot & I hope I've helped,
    Edd.

    Thread moved to tutorials & Guides by --ss-- (Forum Super Moderator): Excellent tutorial!
    Last edited by --ss--; 02-02-2008 at 02:02 PM. Reason: edit.php changed
    i've been here for over 8 years and i don't know why

  2. #2
    Join Date
    Apr 2005
    Posts
    4,614
    Tokens
    90

    Latest Awards:

    Default

    Very nice, well done!

  3. #3
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Better than mine. Alot better. but copy much?
    How could this hapen to meeeeeeeeeeeeeee?lol.

  4. #4
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    796
    Tokens
    0

    Default

    Warning: Cannot modify header information - headers already sent by (output started at /home/www/simplydj.freehostia.com/preview/config.php:13) in /home/www/simplydj.freehostia.com/preview/login.php on line 16

    Warning: Cannot modify header information - headers already sent by (output started at /home/www/simplydj.freehostia.com/preview/config.php:13) in /home/www/simplydj.freehostia.com/preview/login.php on line 17


    NONE of the codes work
    Thanks,
    Chris
    Free Image Uploading

    __________________


    [/url]

    [/FONT]

  5. #5
    Join Date
    Jan 2008
    Posts
    287
    Tokens
    0

    Default

    Quote Originally Posted by chrisgocrazyH View Post
    Warning: Cannot modify header information - headers already sent by (output started at /home/www/simplydj.freehostia.com/preview/config.php:13) in /home/www/simplydj.freehostia.com/preview/login.php on line 16

    Warning: Cannot modify header information - headers already sent by (output started at /home/www/simplydj.freehostia.com/preview/config.php:13) in /home/www/simplydj.freehostia.com/preview/login.php on line 17


    NONE of the codes work
    Your host sucks.

    You do know how insecure this is.

    I could create a cookie called loggedin with the value = yes, and be in.

  6. #6
    Join Date
    May 2007
    Location
    Brisbane, Australia
    Posts
    796
    Tokens
    0

    Default

    im only using Freehostia atm becoz my optus provider has blocked off the port for simplyhabbo.com at home so when i get it back today i should get it to work..
    Thanks,
    Chris
    Free Image Uploading

    __________________


    [/url]

    [/FONT]

  7. #7
    Join Date
    Jan 2008
    Posts
    287
    Tokens
    0

    Default

    Well it seems FreeHostia is blocking an important function that you need

  8. #8
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    I made a maintenance system in housekeeping sort of,

    I used the DJ says tables and Alert, cos I can't code php =)

  9. #9
    Join Date
    Apr 2006
    Location
    Leamington Spa
    Posts
    1,375
    Tokens
    72

    Latest Awards:

    Default

    Quote Originally Posted by Caleb View Post
    You do know how insecure this is.

    I could create a cookie called loggedin with the value = yes, and be in.
    Yes, I do know how insecure this is... It's intended for beginners.
    That means someone whos new?
    God, what happened to the nice Caleb? >_>

    If it was intended for more advanced coders then I'd have used sessions.
    Cookies are simple and are good for a PHP first-time programmer.

    EDIT: Just noticed a huge error in edit.php:
    Replace the previous edit.php code with this code: (I'd be greatful if a Moderator could replace the current edit.php file with the one below on the first post please!)
    PHP Code:
     <?php
    require("config.php"); //Includes the configuration file.
    if($_COOKIE[loggedin] == "yes"){ //If they're logged in...
            
    if(!isset($_POST['update'])){ //Check to see if they've posted the form yet.
                
    echo("Please choose the setting to edit here:<br />
                <form method=\"post\">
                Site Status: <select name=\"status\"><option value=\"on\">On</option><option value=\"off\">Off</option></select>
                <br />
                Offline Message: <input type=\"text\" name=\"offmsg\" size=\"40\">
                <br />
                Online Page To Redirect To: <input type=\"text\" name=\"onpage\" size=\"30\">
                <br />
                <input type=\"submit\" value=\"Update!\" name=\"update\">
                </form>"
    );
                
    //^^ Show them the form because they haven't posted it yet.
            
    }else{ //If they have posted the form...
                
    $status $_POST['status']; //Makes the variable easier to handle.
                
    $offmsg $_POST['offmsg']; //Makes the variable easier to handle.
                
    $onpage $_POST['onpage']; //Makes the variable easier to handle.
                
    mysql_query("UPDATE `sitestatus` SET `status` = '" $status "', `offmsg` = '" $offmsg "', `onpage` = '" $onpage "' ;"); //Updates the MySQL database with the information they specified in the form.
                
    echo("The site has been succesfully updated!"); //Tells them that the database has been updated.
                 
    setcookie("loggedin","",time() - 3600); //Unsets the logged in cookie.
             
    //End the if statement (if have(n't) posted the form yet.
    }else{ //If they're not logged in...
        
    die("Please login to edit the site status!"); //End the if statement(if they're (not) logged in.
    //End the if statment (if not logged in)
    mysql_close(); //Closes any remaining MySQL connections.
    ?>
    Last edited by lolwut; 02-02-2008 at 12:11 PM.
    i've been here for over 8 years and i don't know why

  10. #10
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by lolwut View Post
    Yes, I do know how insecure this is... It's intended for beginners.
    That means someone whos new?
    God, what happened to the nice Caleb? >_>

    If it was intended for more advanced coders then I'd have used sessions.
    Cookies are simple and are good for a PHP first-time programmer.

    EDIT: Just noticed a huge error in edit.php:
    Replace the previous edit.php code with this code: (I'd be greatful if a Moderator could replace the current edit.php file with the one below on the first post please!)
    PHP Code:
     <?php
    require("config.php"); //Includes the configuration file.
    if($_COOKIE[loggedin] == "yes"){ //If they're logged in...
            
    if(!isset($_POST['update'])){ //Check to see if they've posted the form yet.
                
    echo("Please choose the setting to edit here:<br />
                <form method=\"post\">
                Site Status: <select name=\"status\"><option value=\"on\">On</option><option value=\"off\">Off</option></select>
                <br />
                Offline Message: <input type=\"text\" name=\"offmsg\" size=\"40\">
                <br />
                Online Page To Redirect To: <input type=\"text\" name=\"onpage\" size=\"30\">
                <br />
                <input type=\"submit\" value=\"Update!\" name=\"update\">
                </form>"
    );
                
    //^^ Show them the form because they haven't posted it yet.
            
    }else{ //If they have posted the form...
                
    $status $_POST['status']; //Makes the variable easier to handle.
                
    $offmsg $_POST['offmsg']; //Makes the variable easier to handle.
                
    $onpage $_POST['onpage']; //Makes the variable easier to handle.
                
    mysql_query("UPDATE `sitestatus` SET `status` = '" $status "', `offmsg` = '" $offmsg "', `onpage` = '" $onpage "' ;"); //Updates the MySQL database with the information they specified in the form.
                
    echo("The site has been succesfully updated!"); //Tells them that the database has been updated.
                 
    setcookie("loggedin","",time() - 3600); //Unsets the logged in cookie.
             
    //End the if statement (if have(n't) posted the form yet.
    }else{ //If they're not logged in...
        
    die("Please login to edit the site status!"); //End the if statement(if they're (not) logged in.
    //End the if statment (if not logged in)
    mysql_close(); //Closes any remaining MySQL connections.
    ?>
    Yes hi edd (ty for ignoring me on msn (N))

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •