PDA

View Full Version : Site Status Page.



lolwut
25-03-2007, 08:54 AM
My first ever peice of PHP coding. Please be constructive when criticising it :)

Sorry I didn't really know where this is supposed to go. If it's in the wrong place can a Mod move it?

Page: index.php


<?php

$sitestat = "off"; //Change this to on or off. NOTE: Chaning it to something other than on or off will result in the user not being able to access the site, even if it's on!

if ($sitestat == "off") {
echo "<font color=\"Red\" size=\"3\" face=\"Verdana\">Site Offline!</font>"; // Only bit you need to edit.
} elseif ($sitestat == "on") {
echo "<font color=\"Green\" size=\"3\" face=\"Verdana\">Site Online.
<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=main.php\"></font>"; // Only bit you need to edit.
} else {
echo "Sorry, your admin didn't set the status for the website... The valid statuses are <b>off</b> and <b>on</b>.";
}
//------------------------------------------------------------------------------------//
// Edit what I told you not to edit (if you don't know PHP). The script may not work! //
//------------------------------------------------------------------------------------//

?>

omgDAN!
25-03-2007, 08:57 AM
Wow nice coding for a first.
Maybe you could find some other ways of doing re-directs.

lolwut
25-03-2007, 10:36 AM
Tyvm :D

I will do more as I learn more PHP... I was working on a password preotected page to change the status, but it didn't work right. As I'd need MySQL and tbh I cba with it.

timROGERS
25-03-2007, 11:31 AM
Here's the code for a redirect:



<?php
header("Location: where to do");
?>

lolwut
25-03-2007, 04:05 PM
Ty.

VERSION 2:


<?php

$sitestat = "off"; //Change this to on or off. NOTE: Chaning it to something other than on or off will result in the user not being able to access the site, even if it's on!

if ($sitestat == "off") {
echo "<font color=\"Red\" size=\"3\" face=\"Verdana\">Site Offline!</font>"; // Only bit you need to edit.
} elseif ($sitestat == "on") {
echo "<font color=\"Green\" size=\"3\" face=\"Verdana\">Site Online.
header("Location: page.php");
</font>"; // Only bit you need to edit.
} else {
echo "Sorry, your admin didn't set the status for the website... The valid statuses are <b>off</b> and <b>on</b>.";
}
//------------------------------------------------------------------------------------//
// Edit what I told you not to edit (if you don't know PHP). The script may not work! //
//------------------------------------------------------------------------------------//

?>
If a mod can merge this with the original post I'd be greafull ;]

sBosma
25-03-2007, 04:11 PM
echo "<font color=\"Green\" size=\"3\" face=\"Verdana\">Site Online.
header("Locationpage.php");
</font>"; // Only bit you need to edit.
} else {

You forgot to add the back slashes in front of the quotes. Pretty good for a first. I'm learning PHP too.

Invent
25-03-2007, 04:22 PM
Nope your advice is wrong.

Remove the: header(""); from the echo. It shouldnt be there.

Drompo
25-03-2007, 06:28 PM
Would be better with an input field and a databse but good for a first attempt

lolwut
25-03-2007, 06:55 PM
Would be better with an input field and a databse but good for a first attempt

Yeah I tryed but everything broke.

Want to hide these adverts? Register an account for free!