PHP code to check server status
Tuesday, October 3rd, 2006Borntwisted came up with a wonderful idea to check that his free host was running without having to visit the a page or check the ftp.
He wrote a short piece of HTML that would pull an image off his website, if the server failed to respond the ALT tage would display OFFLINE.
I like to code things in php so I decided to take this a step further and not actually use any images, thus saving on bandwidth on my server everytime the page loads.
The full code is at the bottom of this post but I am going to break it down and try to explain how each section works.
First of all we need to connect to the server and check to see if a file exists. This file can be anything you like, I chose to use an image called online.gif.
I declared a variable call $url which holds the data needed to connect to the server. @fopen is the php command to connect to the server and open the chosen file. The reason the @ symbol is used is to supress the error that will be returned when the file cannot be found.
Using "r" tells the command we want to open the file in read only mode.
-
<?
Now we use a simple ifelse statment to output the correct part of the formula.
The first part of the formula as below asks if the condition is true (if file exists) and will output the command below it.
-
if ($url) {
Before the command is outputted we have to close the connection to the file for security purposes. fclose closes the connection to the server which is defined again by our variable $url.
Now we can output the following command if the file is found on the server. Basically this is the TRUE part of the conditional statement. We now ECHO a line of code to the browser which will be converted into HTML and displayed as what you will see. Do not worry about the div's and classes, that is just CSS styling for the page I have this code on.
-
}
The following code is the FALSE part of the staement, which is outputted if the above connection cannot find the file. It has similar styling to the above command but this time you will notice that the div class is set to "offline". This is so a different colour is displayed.
-
else {
-
}
-
?>
That's all there is to it. The code is simple and works well. If you use this code you may notice that when the file is removed by yourself the script doe snot update, this is simply because of the server it is on. Sometimes servers take a few minutes to update.
The code as a whole is listed below and I have also added the CSS that I have used. Modify to your needs.
-
.holder{
-
width:80px;
-
margin-left:5px;
-
}
-
-
.name{
-
float:left;
-
}
-
-
.online{
-
text-align:center;
-
width:8px;
-
height:8px;
-
padding:2px;
-
background:#75f475;
-
float:right;
-
border:1px solid #000;
-
margin-bottom:2px;
-
}
-
-
.offline{
-
text-align:center;
-
width:8px;
-
height:8px;
-
padding:2px;
-
background:#ef2424;
-
float:right;
-
border:1px solid #000;
-
margin-bottom:2px;
-
}
Dynamic Menus for WordPress
Thursday, April 27th, 2006The standard WordPress navigation menu is limited in that it does not show sub menus. it will list every single page on your website in one long list in the navigation section.
For larger sites this can become troublsome. Who wants 50 links running down the side of the page just for the content. It can also be very confusing to site visitors.
I decided I needed a simple script to display the sub menu only when the parent page was clicked, - a working example of this is on the right hand side of this page - so I wrote a little script to do this, and in the spirit of open source, here is the turorial so that you can make it yourself.
Styling individual comments for WordPress
Thursday, April 20th, 2006I wanted a little script that would allow me to have specific styles for individual comments depending on the authour.
I had a look around for WordPress plugins and other info, but could not find anything that actually worked.
So I wrote my own little switch statment to sort it all out.
-
<?php
-
switch (comment_author_email){
-
case ($comment->comment_author_email == 'friend@friend.com'):
-
$style = '<div class="friendcomment">';
-
break;
-
case ($comment->comment_author_email == 'you@you.com'):
-
$style = '<div class="authorcomment">';
-
break;
-
default:
-
$style = '<div class="defaultcomment">';
-
break;}?>
-
This involves modifying the comments.php file in your theme folder.
Find:
-
<cite><?php comment_author_link() ?></cite>
And add this code above that line: Make sure you put the correct email addresses in.
-
<?php
-
switch (comment_author_email){
-
case ($comment->comment_author_email == 'friend@friend.com'):
-
$style = '<div class="friendcomment">';
-
break;
-
case ($comment->comment_author_email == 'you@you.com'):
-
$style = '<div class="authorcomment">';
-
break;
-
default:
-
$style = '<div class="defaultcomment">';
-
break;}?>
-
Now find:
-
<?php comment_text() ?>
Add the following on the line below:
-
</div>
That's it for the comments.php file.
Now open your style sheet, usually called style.css and add the following rules to the end of your style sheet, modify to yoru own needs.
-
.authorcomment {
-
background: #ffffcc;
-
padding:10px;
-
border:2px solid #000;
-
color:#333;
-
min-height:90px;
-
}
-
.friendcomment {
-
background: #fff;
-
padding:10px;
-
border:2px solid #000;
-
color:#333;
-
min-height:90px;
-
}
-
.defaultcomment {
-
background: #eee;
-
padding:10px;
-
border:2px solid #000;
-
color:#333;
-
min-height:90px;
-
}
Thats everything. Save and upload your files and see for yourself.
New Wordpress Theme and Mod available
Monday, April 10th, 2006Morning Theme
Quite aptly named, since it was very early in the morning that I created this
Wordpress has hundreds of themes out there for you to choose from. I know there to be at least 700 as I search through a huge list looking for something that would suit my needs.
Each to there own though, because I couldnt find one remotely close to what I wanted. So, after 2 hours I had my first layout up and running. Since then I have been tinkering with the style and finally made this.
It is by no means the last style I will create, but for now it is here to stay.
You can find this Theme in the downloads section under Wordpress Themes and Mods. But, if your too lazy to click through to there, you can just click here
Festive Images
On that same page you will find the Festive Images mod. You can also see it running at the top of this site. Just wait till Easter. It allows you to have a certain image show up on a certain day. Ideal for having your Cristmas logo displayed over Cristmas, and you will not have to remember to upload it and edit the file.
Once you have added your dates to the script, and told it where to find each new image. just save it, upload it and your done.
Automation at its best.
Good Shades, Bad Colours
Wednesday, April 5th, 2006In a chat with SoddenGecko i thought up this method for changing a sites colours when you have the shades right, but not quite the right colours. I'm too lazy to type it into a colour tutorial at the moment so heres the pasted chat message:
"if your thinking yea it blends well but i didn't want a tan site, then take a screenshot, take that into photoshop, then open the hue and saturation window and change the colour till you like it, then sample the colours and replace them in css, voila"
Search
Previous Posts
- How to: Install Ubuntu packages with HTML link Posted by Soddengecko March 15, 2008
- How to: Increase ext3 and reiserfs performance Posted by Soddengecko March 11, 2008
- Mount network shares at boot. (Ubuntu) Posted by Soddengecko March 10, 2008
- Citrix ICA Client install on Ubuntu (Feisty and Gutsy) Posted by Soddengecko March 10, 2008
- mod_rewrite on Apache(2) Server Posted by Soddengecko March 10, 2008
- Multi-TouchScreen Computing Posted by Soddengecko June 7, 2007
- Install Lexmark Printers (Ubuntu) Posted by Soddengecko September 28, 2006
- Have Xampp run at boot time Posted by Soddengecko September 27, 2006
- Fix Firefox sound issues (Ubuntu Dapper) Posted by Soddengecko September 27, 2006
- Realplayer Sound fix (Ubuntu all versions) Posted by Soddengecko September 27, 2006
Recently Updated
Archives
People
Linkies
- Matthew Moore This blog belongs to an associate of mine. He likes to jibber jabber on a bit, and he has decided to document his exercising habits lately, but look back and check out some of the good stuff. Added on March 22nd, 2008 @ 12:08
- Fight for Kisses Probably the best shaving advert I have seen. Not much by the way of pretentious bullshit and it actually has a couple of funny moments. Worth a watch. Added on October 25th, 2007 @ 09:52
- Speedtest.net Speedtest.net is a broadband connection analysis tool with a huge selection of geographically dispersed testing servers. Ookla provides this service free to hundreds of thousands of people every day. If you are experiencing slowness with your Internet connection or are simply interested in testing your speed, Speedtest.net is for you. Added on October 15th, 2007 @ 22:09
- Sadikhov Forums A forum of like minded people helping others achieve the coveted CCNA qualification. The site is aimed at helping those understand the complex issues presented in the exams and making sure you understand them before wasting your money. Added on October 15th, 2007 @ 22:09
- RouterSim.com RouterSim has been the leader in IT simulation training since 1999. RouterSim's Industry expert Todd Lammle offers you the best learning tools available. We have expanded our offerings to match your budget and needs. RouterSim offers simulators, computer-based training videos, online CCNA simulation testing, and exam preparation software. Added on October 15th, 2007 @ 22:08
- Generic Linux rules of thumb for security The only secure box is turned off and locked in the back room -- but it's also not much use to anyone Added on October 15th, 2007 @ 22:06



by @ 12:36
