PHP question

Alright, so I’ve got my radio show’s site up right now. (It’s http://www.billfredinthenighttime.com if you’re interested.)

I’m trying to come up with a way to send up an alert (displaying an image) that I’m on the air at that time without having to dive into the HTML. My host supports PHP (in fact, that’s how I got the nifty random image at the top going), but I honestly don’t know a thing about it.

So, can someone point me to a way to do that? Or even better, point me to a way to learn to do that?

I learned PHP by reading the documentation (www.php.net), but I’m not sure if that’s the best way for you to find what you’re looking for. I can’t say I’ve ever had to do something like that, but perhaps you could run a few search strings in Google, and find something? Anything I can think of at the moment is needlessly complicated for what you’re looking for.

Or, you could ask our benevolant forum overload (Brandon for short), because the forums have that little “LED” that turns green if a user has logged on. Perhaps you can get some code from that (or he can help write some code from that)?

I got my first taste of PHP at www.w3schools.com
Then I later bought a book. I run my own forums and so forth, I’m guessing that the LED thing works by basically: when the user logs on, set a value in the SQL database to “on”, so when you call a page which display’s the username, it will show the online image (which is the green LED). When the user logs off, the opposite happens and you see a red LED. May sound confusing… I can’t think of any better way to put it.
And I could be very very very wrong.
Also, you’re still going to need to use some HTML when writting your own PHP scripts. Maybe you can try googling for a script that does what you want?

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

$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:  <input type="password" name="passwd" />
<br />
Status:  
<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:

..... <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 :slight_smile:

Jack

PS: If you would rather have your status change automatically depending on the date/time, you could have that instead.

That’s perfect!

(And I think I’ll just keep it so I can flip it manually. I substitute fairly often for other shows, so I’m not always on when I think I will or won’t be.)

Leave it to Chief Delphi to have all the 1337 (but graciously professional) h4x0rz.