Thread: PHP question
View Single Post
  #4   Spotlight this post!  
Unread 13-10-2004, 00:52
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
Re: PHP question

Alrighty..

First off, you're going to need to change the extention of index.html to index.php (Be sure to update any links you have on your site to index.html )

Next, because we want to keep this as simple as possible, create a file in same directory where index.php is located and call it status.txt You'll need to be sure that this file is writeable by the webserver. (That means to change it's mode to 644 or 664 or 666, one of those should work. You can change the file's mode in your ftp client.)

Next, create the file status.php and paste this as its contents:
PHP Code:
<?php

$passwd 
'YOUR PASSWORD';  //Change this value!!

if (isset($_POST['submit']))
{
    if (
$_POST['passwd'] == $passwd)
    {
        
$fp fopen('status.txt''w');
        
fwrite($fp$_POST['status']);
        
fclose($fp);
    } else {
        echo 
'<b>Invalid Password!!</b><hr />';
    }
}

?>
<html>
<body>
<h3>Change Status</h3>
<form action="status.php" method="post">
Password:&nbsp;&nbsp;<input type="password" name="passwd" />
<br />
Status:&nbsp;&nbsp;
<select name="status">
    <option value="off" selected>Off</option>
    <option value="on">On</option>
</select>
<br />
<input type="submit" name="submit" value="Update Status" />
</form>
</body>
</html>
Change the YOUR_PASSWORD to what you would like the status updateing password to be. (Leave the ' ' around your password, but you don't enter them when you enter your password.) Whenever you want to change your on-air status, go to http://www.billfredinthenighttime.com/status.php, enter your password, pick the new status, and click update.

Next, insert the php code below in the spot in your index.php file where you want to display your status. For example:
PHP Code:
..... <a href="aboutbillfred.html">about Billfred</a> | <a href="aboutbitn.html">about BitN</a> | <a href="oldnews.html">older news</a> | <a href="links.html">links</a> | <a href="downloads.html">downloads</a> | <a href="http://wusc.sc.edu">WUSC</a>
<br><br> <?php

$status 
trim(strtolower(file_get_contents('status.txt')));

switch (
$status)
{
    case 
'on':
        
?>
            PUT HTML FOR 'ON' HERE
        <?php
        
break;
    default:
        
?>
            PUT HTML FOR 'OFF' HERE
        <?php

}

?>..... Uhm, hi.<br><br>

If you're reading this, you've obviously found my website.  Sucker--erm, <i>lucky you!</i><br><br>
Change the PUT HTML FOR blah.. to whatever html you would like to display for your on or off status.

This isn't the most graceful way of updateing your status, but it's pretty quick and very functional. If ya have any questions, ask and someone should be able to help

Jack

PS: If you would rather have your status change automatically depending on the date/time, you could have that instead.
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**