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 3 123 LastLast
Results 1 to 10 of 27
  1. #1
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default [PHP][TUT]Maintenance Page[EASY/MEDIUM]

    Ok - this is my first tut hope you like it the projects name is "ProWebMaintenance" after http://www.prowebdesigns.co.uk/
    OK open up your index.php file of your website if you have a .htm/.html or any other extension please change it to .php

    Ok right at the very top even above stating your document C+P this:
    PHP Code:
    <?php // this starts PHP coding. a bit like <html>
    error_reporting(0// this turns off error_reporting for stuff like notices
    $host "*usually localhost*"// this is your host
    $user "*username*"// your username
    $db ="*yourDB*"// your database
    $pass "*password*"// your password
    mysql_connect($host$user$pass); // connect function with your vars
    mysql_select_db($db); // selecting your database
    $query 'SELECT status FROM `status`'// this is your SQL query
    $result=mysql_query($query); // this makes the SQL query
    $status mysql_fetch_assoc($result); // this makes sense of the results.
         
    if($status[status] == "offline") die("This website is under maintenance, please check back later"); // this is asking if the status is equal to 'offline' then kill the rest of the script and display an error message
    ?>  // closes php with the closing tag
    Please if you want to know how it works read the comments
    OK heres what you need to inject into your SQL:

    Code:
    CREATE TABLE IF NOT EXISTS `status` (
      `status` text
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    --
    -- Dumping data for table `status`
    --
    
    INSERT INTO `status` (`status`) VALUES
    ('online');
    Rather self-explanatory as things mean what they are - eg insert inserts, select selects, create table if not exists creates a table if it doesn't exist, etc...
    OK now - we want somewhere where we can turn the site on and offline - i myself am quite new to php, so i embedded this into a pre-built user system, i advise you to do the same unless you want people turning your site on and of so this is the page i made:

    updatestatus.html
    HTML Code:
    <form method="post" action="updated.php"> 
    Status changer:
    Status: (Choose offline or online)<input type="text" name="ud_status">
    </form>
    lets look over this code, we first open a form tag and then we choose the action updated.php , the inputs name is ud_status for future reference.

    now

    updated.php

    PHP Code:
    <?php // opens php
    $ud_status=$_POST['ud_status']; // gets the inputted text
    $host "*host*"// your host
    $user "*username*"// your username
    $db "*yourDB*"// your db
    $pass "*pass*"// your password
    mysql_connect($host$user$pass); // connects to mysql
    mysql_select_db($db); // selects the db
    $query="UPDATE status SET status = '$ud_status'"// the query  to update the field to a new text.

    mysql_query($query); // queries mysql
    echo "Record Updated"// confirmation of updating
    mysql_close(); // closes mysql.

    ?> // closes php
    once more please read the comments in order to understand the coding.

    Last thing - when the site is online you can use this code within your html code using a .php extension to display that the site is online.

    PHP Code:
    <span class="sidetext">Site is <font color="#00FF00"><b><i>
    <?php
         
    echo "$status[status]";
    ?>
         </font></span>
    Hope you enjoyed the tutorial

    - Charlie
    Last edited by Hypertext; 01-02-2008 at 05:40 AM. Reason: Name
    How could this hapen to meeeeeeeeeeeeeee?lol.

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

    Default

    Parse error: parse error, unexpected T_VARIABLE in /home/www/simplydj.freehostia.com/preview/index.php on line 3

    ??
    Thanks,
    Chris
    Free Image Uploading

    __________________


    [/url]

    [/FONT]

  3. #3
    Join Date
    Sep 2007
    Location
    USA
    Posts
    474
    Tokens
    0

    Default

    i beleive you should have put localhost

    all lowercase if thats not working post back here with your coding and well see if memebers can help you
    Post Meter
    ______________________________________________
    400 450 500 550 600 650 700 750 800 850 900-1k
    Green=Done | Orange=Almost | Red=Not Done
    ______________________________________________
    Habbo fury Coming Soon!
    My Img tag has ran away

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

    Latest Awards:

    Default

    OK Tut I suppose, +rep.

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

    Default

    Okay, you are putting PHP comments, outside of PHP, duh?

    Learn how to clean your code, that looks absolutely awful, and I can't even read through it.

    I do see however that you are not cleaning your inputs, which means SQL injection, and other flaws like XSS.

    No curley brackets? What is wrong with you.

    Clean code:

    PHP Code:
    <?php
    $host 
    "localhost";
    $user ""// your MySQL username
    $db ""// your  MySQL database
    $pass ""// your MySQL password
    mysql_connect $host$user$pass ); // Connects to DB.
    mysql_select_db $db ); // selecting your database


    $query mysql_query "SELECT status FROM status" ); // this makes the SQL query
    $status mysql_fetch_array $query );

    if (
    $status ["status"] == "offline") {
        echo 
    "This website is under maintenance, please check back later.";
        exit ();
    }
    ?>
    Also, why connect at each page? You could simply just have a config file doing all of this for you, wasted space, wasted typing. Do it once.

  6. #6

    Default

    Dude seriously, clean up your code, why havn't you used braces after your if statement and why do you set a variable for your querys before executing them? that's just a waste of time.. I guess it does the job but you could have included the ability to set an offline message rather than having a pre-determined one. Also, it's not very secure anyone can access the page to turn your site offline/online and since you've not used a drop down with pre-determined values they can enter anything. I woulnd't recommend using this for your site.

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

    Latest Awards:

    Default

    I said it was my first tut, please post your code if you get any errors, and as for the comments I just added them in - sorry about that ;/
    How could this hapen to meeeeeeeeeeeeeee?lol.

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

    Default

    Still, you need to code WAY cleaner, that reminds me of my old code.

    It may be your first tut, but you should have some basic coding concepts since you are a(n) MCSD :|

  9. #9
    Join Date
    Jan 2008
    Posts
    534
    Tokens
    0

    Default

    Quote Originally Posted by Caleb View Post
    Still, you need to code WAY cleaner, that reminds me of my old code.

    It may be your first tut, but you should have some basic coding concepts since you are a(n) MCSD :|
    MCSD? XDD

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

    Default

    Yes, he believes he is a Microsoft Certified Solution Developer, which he is not.

Page 1 of 3 123 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
  •