This post really has no central issue but I have been doing a few things the past few days to help upgrade d3vious a little bit and make it better.
Spam Robots!
Well for starters, I always check my comments to see who is around and about my blog and commenting and one day I saw 18 comments on my first blog post. Well at first I was thinking, "WOW did everyone just read that or what am I missing here". So all excited, I went to go read them and quickly got sad. What is the reason for this you ask?!? Well besides the 2 or 3 faithful and true comments, there were about 15-16 blog robot comments! Well this pissed me off and because it has happened before but not in this much bulk (last time was like 2 or 3 comments). So what I decided to do about this was add a field to the comments form that asks the user if they are a robot or not. As long as the user inputs "no" "No" or "NO" then there comment will be posted. Anything otherwise, and it will not post the comment. This is sort of a pain in the butt and im sorry, but this is my attempt to stop blog robot spam. HA
Simple PHP Pay Calculator Script
Today I was bored, and was looking at past paychecks from my jobs that I have had in the past years. I was trying to calculate what tax was taken from each and how they differed. Well in doing this I decided to make my own small, and simple script to decide the amount you will get paid, incase you want to know before your pay stub comes in, or before you check your accounts. This script is more based on MY job, and therefore I didn't make it very modular for other taxes that may be used that I don't know about. It is just a simple script that takes hours worked and hourly rate, and decides what your pay will be depending on the taxes you place on it. Once again this script is geared towards Me and my current work situation and is open for anyone to take and use for their own use.
Here is the script.
<?php
// Pay Calculator.
// By: Brandon Green
if(isset($_POST['submit']))
{
$hours = $_POST['hours'];
$rate = $_POST['rate'];
(isset($_POST['federal'])) ? $federal = $_POST['federal'] : $federal = NULL;
(isset($_POST['ssEmployee'])) ? $ssEmployee = $_POST['ssEmployee'] : $ssEmployee = NULL;
(isset($_POST['medicare'])) ? $medicare = $_POST['medicare'] : $medicare = NULL;
(isset($_POST['mdTax'])) ? $mdTax = $_POST['mdTax'] : $mdTax = NULL;
if(empty($hours) || empty($rate))
{
echo "<font color=\"red\">Fill out all Text fields. <a href=\"javascript:history.go(-1)\">[GO BACK]</a></font>";
}
elseif(!(is_numeric($hours)))
{
echo "<font color=\"red\">Hours must be numeric. <a href=\"javascript:history.go(-1)\">[GO BACK]</a></font>";
}
elseif(!(is_numeric($rate)))
{
echo "<font color=\"red\">Rate must be numeric. <a href=\"javascript:history.go(-1)\">[GO BACK]</a></font>";
}
else
{
// It seems nothing has gone wrong, so lets calculate this pay period.
// First Calculate (hours * rate) to get our gross pay.
$grossPay = $hours * $rate;
// Federal was selected, take 10%
($federal != NULL) ? $federalPay = $grossPay * $federal : $federalPay = 0;
// Social Security Employee was selected, take 6.2%
($ssEmployee != NULL) ? $ssEmployeePay = $grossPay * $ssEmployee : $ssEmplyeePay = 0;
// Medicare Employee was selected, take 1.45%
($medicare != NULL) ? $medicarePay = $grossPay * $medicare : $medicarePay = 0;
// MD Income Tax was selected, take 4.1%
($mdTax != NULL) ? $mdTaxPay = $grossPay * $mdTax : $mdTaxPay = 0;
$finalSubtractions = $federalPay + $ssEmployeePay + $medicarePay + $mdTaxPay;
$finalPay = $grossPay - $finalSubtractions;
echo "<p>Your gross pay without taxes is <i>$" . $grossPay . "</i></p>";
if($federal != NULL || $ssEmployee != NULL || $medicare != NULL || $mdTax != NULL)
echo "<p>Your pay, after taxes that you selected, will be approximately: <b>$" . number_format($finalPay, 2, '.', '') . "</b></p>";
echo "<p><a href=\"payCalc.php\">Again?</a></p>";
}
}
else
{
?>
<form action="payCalc.php" method="post">
Hours Worked: <input type="text" name="hours" size="20" /><br />
Rate Per Hour: <input type="text" name="rate" size="20" /><br />
<input type="checkbox" name="federal" value=".10"/> Federal Withholding (10%)<br />
<input type="checkbox" name="ssEmployee" value=".062"/> Social Security Employee (6.2%)<br />
<input type="checkbox" name="medicare" value=".0145"/> Medicare Employee (1.45%)<br />
<input type="checkbox" name="mdTax" value=".041"/> MD - Income Tax (4.1%)<br />
<input type="submit" name="submit" value="Calculate" />
</form>
<?php
}
?>
Im sure there are plenty of shortcuts which could be used to program this and make it more efficient but this is just something i did on the spur of the moment. This is nothing drastic or special but just something I thought I'd share with everyone else!
Go test it out by clicking here! Any comments or suggestions let me know.
- Brandon on Nov 10 said:
- Jordan, thanks man! Note to ALL If you put enough of any number into the script and multiply it, for example 50+ 9s in each box, and then hit submit, you will get the PHP INF phrase. HA
- Jordan on Nov 10 said:
- Haha yeah nice script.
