View Full Version : [PHP][TUT]Maintenance Page[EASY/MEDIUM]
Hypertext
01-02-2008, 05:30 AM
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 // 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:
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 :P so this is the page i made:
updatestatus.html
<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 // 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.
<span class="sidetext">Site is <font color="#00FF00"><b><i>
<?php
echo "$status[status]";
?>
</font></span>Hope you enjoyed the tutorial :)
- Charlie ;)
chrisgocrazyH
01-02-2008, 06:02 AM
Parse error: parse error, unexpected T_VARIABLE in /home/www/simplydj.freehostia.com/preview/index.php on line 3
??
LegendOfNoob
01-02-2008, 03:10 PM
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 :)
Robbie
01-02-2008, 03:14 PM
OK Tut I suppose, +rep.
Caleb
01-02-2008, 04:10 PM
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
$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.
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.
Hypertext
01-02-2008, 06:29 PM
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 ;/
Caleb
01-02-2008, 06:34 PM
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 :|
theJOSH
01-02-2008, 06:43 PM
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
Caleb
01-02-2008, 06:47 PM
Yes, he believes he is a Microsoft Certified Solution Developer, which he is not.
theJOSH
01-02-2008, 06:50 PM
Yes, he believes he is a Microsoft Certified Solution Developer, which he is not.
Lmao! xDD
Edited by H0BJ0B (Forum Moderator): Please do not post pointlessly.
Hypertext
01-02-2008, 08:24 PM
Being MCSD has nothing to do with cleaner code.
Caleb
01-02-2008, 08:32 PM
Being MCSD has nothing to do with cleaner code.
1. Your not a MCSD.
2. People of a high rank and status such as that, code clean and efficient.
Baving
01-02-2008, 08:51 PM
Being MCSD has nothing to do with cleaner code.
Technically it does.
Part of the certification process establishes whether or not you are able to program in clean and efficient program structures. For example:
- Functions
- Classes
- Non-Repetitive Code
- Programmers initiative to overcome problems logically so that future viewers of the source can understand how the system works.
Certification is not just about knowledge, it requires all aspects of programming to be covered and met to a required standard.
The way you have done this site off line script is a very bad way of doing it.
--ss--
01-02-2008, 09:24 PM
Not bad but as already said by others it's not very neat :(.
Also it's a good idea if you're going to make a web design company that you make you're site is XHTML valid ;).
chrisgocrazyH
01-02-2008, 09:28 PM
so has anyone got help with my probleam or what
Hypertext
01-02-2008, 10:43 PM
so has anyone got help with my probleam or what
Post your full code please I followed the directions and it worked ;S
Not bad but as already said by others it's not very neat :(.
Also it's a good idea if you're going to make a web design company that you make you're site is XHTML valid ;).
What can I say - I'm starting out, it should be HTML 4.01 Transitional, but I'll check it out, I'll try and revise it tonight and repost a better one.
chrisgocrazyH
01-02-2008, 11:23 PM
<?php // this starts PHP coding. a bit like <html>
error_reporting(0) // this turns off error_reporting for stuff like notices
$host = "**** OFF YOU HACKER IM NOT POSTING MY DETAILS"; // this is your host
$user = "**** OFF YOU HACKER IM NOT POSTING MY DETAILS"; // your username
$db ="**** OFF YOU HACKER IM NOT POSTING MY DETAILS"; // your database
$pass = "**** OFF YOU HACKER IM NOT POSTING MY DETAILS"; // 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
<html><head><title>SimplyHabbo.com ~ Were Back Omggzz ~</title>
<link href="images/blue.css" rel="stylesheet" type="text/css">
</head>
<body style="background-image: url('http://habboring.com/goodies/webbgs/newbg_blue.gif')">
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<tbody><tr>
<td background="images/titlebars/blue/title_bar.PNG" height="85">
<img border="0" src="font_1201419153.gif" width="223" height="24"></td>
</tr>
</tbody></table>
<center>
<table style="margin-bottom: 4px;" border="0" cellpadding="0" cellspacing="0" id="table1" width="696">
<tr>
<td align="left" valign="middle" width="8" style="border-right-style: none; border-right-width: medium">
<img src="left.gif" height="20" width="8"></td>
<td style="font-family: Tahoma; font-size: 11px; background-image: url('url(bg.png');border-left-style:none; border-left-width:medium; border-right-style:none; border-right-width:medium; border-top-style:solid; border-top-width:1px; border-bottom-style:solid; border-bottom-width:1px" valign="top" bgcolor="#FFFFFF">
<div id="message">
DJ Says: Welcome to SimplyHabbo!<br />
</div>
</td>
<td align="right" valign="middle" width="9" style="border-left-style: none; border-left-width: medium">
<img src="right.gif" height="20" width="9"></td>
</tr>
</table>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody><tr>
<td valign="top">
<table border="0" cellpadding="4" cellspacing="0" width="190">
<tbody><tr>
<td background="images/navtitle.gif" height="23">
<font color="#FFFFFF"><b> Navigation</b></font></td></tr>
<tr>
<td background="images/subbg.PNG">
<a href="index.php?page=home">Hello</a><br>
<a href="index.php?page=news">Hi</a><br>
</td>
</tr>
<tr>
<td background="images/subbottom.gif" height="10">
</td>
</tr>
</tbody></table>
<br>
<table border="0" cellpadding="4" cellspacing="0" width="190">
<tbody><tr>
<td background="images/usrsys.gif" height="23">
<b><font color="#FFFFFF"> Usersystem </font><font color="#FF0000" size="1">
New!</font></b></td></tr>
<tr>
<td background="images/subbg.PNG">
<iframe width="174" height="163" name="usr" border="0" frameborder="0"></iframe></td>
</tr>
<tr>
<td background="images/subbottom.gif" height="10">
</td>
</tr>
</tbody></table>
</td>
<td width="10">
</td>
<td valign="top">
<table border="0" cellpadding="4" cellspacing="0" width="501">
<tbody><tr>
<td background="images/maintitle.gif" height="23">
<font color="#FFFFFF"><b> SimplyContent </b></font>
</td></tr>
<tr>
<td background="images/mainbg.PNG">
<?php
$_GET['page'];
if($page == "home")
{
include('home.php');
}
elseif($page == "news")
{
include('news.php');
}
else
{
include('home.php');
}
?> </td>
</tr>
<tr>
<td background="images/mainbottom.gif" height="10">
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
<br>
<table border="0" cellpadding="5" cellspacing="0" width="700">
<tbody><tr>
<td class="disclaimer" background="images/titlebars/blue/disclaimer_bar.GIF" height="25">
<font color="#ffffff">
Copyright © 200</font><font color="#FFFFFF">7 > 2008 SimplyHabbo.com</font></td>
</tr>
</tbody></table>
<br>
</center></body></html>
Hypertext
02-02-2008, 12:46 AM
Seems ok, please post the other 2 files updated.php and status.php or w.e
chrisgocrazyH
02-02-2008, 02:05 AM
dont worry now im making a cms :)
Independent
02-02-2008, 12:58 PM
dont worry now im making a cms :)
Seeing as you couldn't realise what the error was, I highly doubt you'll get past line 1 in your ''CMS''
--ss--
02-02-2008, 01:05 PM
Post your full code please I followed the directions and it worked ;S
What can I say - I'm starting out, it should be HTML 4.01 Transitional, but I'll check it out, I'll try and revise it tonight and repost a better one.
Well if you want to revise I suggest you make it so all your varibles like the <td>'s and <tr>'s are in lower case as XHTML disallows capitals in the variable names ;).
dont worry now im making a cms :)
You wouldn't no where to start..
Well if you want to revise I suggest you make it so all your varibles like the <td>'s and <tr>'s are in lower case as XHTML disallows capitals in the variable names ;).
Why doesnt it allow <img> tags?
I found that when i tried one..
--ss--
02-02-2008, 03:36 PM
Why doesnt it allow <img> tags?
I found that when i tried one..
For variables that doesn't have another matching variable to close the element you will have to add a / to end of it ,like the image and new line tags.
<img src=URL> becomes <img src="URL" alt="text" />
<br> becomes <br />
You do not need to add / to things like bold , italic or embed tags as they have matching tags like
<b> has </b>
<i> has </i>
<embed> has </embed>
etc
I hope that makes seance :)
For variables that doesn't have another matching variable to close the element you will have to add a / to end of it ,like the image and new line tags.
<img src=URL> becomes <img src="URL" alt="text" />
<br> becomes <br />
You do not need to add / to things like bold , italic or embed tags as they have matching tags like
<b> has </b>
<i> has </i>
<embed> has </embed>
etc
I hope that makes seance :)
Yes it does, thanks
If you are really a MCSD link us to your MCP profile.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.