How to create a basic rating system
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“DTD/xhtml1-transitional.dtd”>
<html>
<body>
<?php if ( (!isset($_POST[’submit’])) ) { ?>
<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>“ method=”post”>
<table>
<tr>
<td>Your rating:</td>
<td><select name=”rate”>
<option value=”1″>1</option>
<option value=”2″>2</option>
<option value=”3″>3</option>
<option value=”4″>4</option>
<option value=”5″>5</option>
</select></td>
</tr>
<tr><td colspan=”2″ align=”center”>
<input type=”submit” value=”Rate it!” name=”submit”/>
</td></tr>
</table>
</form>
<?php
} else {
$rate = isset ($_POST[‘rate’]) ? $_POST[‘rate’] : 0;
$filename = “ratings”;
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;
$ip = getenv(‘REMOTE_ADDR’);
// Read the result file
$oldResults = file(‘results/’.$filename.‘.txt’);
// Summarize total points and rates
foreach ($oldResults as $value) {
$oneRate = explode(‘:’,$value);
// If our IP is in the list then set the falg
if ($ip == $oneRate[0]) $alreadyRated = true;
$totalRates++;
$totalPoints += $oneRate[1];
}
// If our rating is valid then append it to the result file
if ((!$alreadyRated) && ($rate > 0)){
$f = fopen(‘results/’.$filename.“.txt”,“a+”);
fwrite($f,$ip.‘:’.$rate.“\n”);
fclose($f);
$totalRates++;
$totalPoints+=$rate;
}
echo “Actual rating from $totalRates rates is: ”
.substr(($totalPoints/$totalRates),0,3).“<br/>”;
// Display the actual rating
for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){
echo “<img src=’style/star.png’ />”;
}
} ?>
</body>
Code Snippet: Date converter
Snippet: Date converter
Description:
This tiny piece of code takes care that you can display a standard date instead of the mysql date (2005-02-23)
Example:
echo date(”d m Y”, “2005-02-23″);
Shows:
23 02 2005
Code:
PHP:
Snippet: Are sessions working?
Description:
You can use this piece of code to check if it is possible to use sessions for the visitor.
This can come handy for login pages. If you have cookies disabled and try to login, no login session can be used. In such cases it is nice to inform […]
Code Snippets: Calculate Age
Snippet: Calculate age
Description:
With this function you can calculate the age of a person
Example:
echo “Age is: ” . birthday (”1984-07-05″);
Result will be (23 Feb 2005) = “Age is: 20″
Code:
PHP:
<?php
//calculate years of age (input string: YYYY-MM-DD)
function birthday ($birthday){
list($year,$month,$day) = explode(“-”,$birthday);
$year_diff = date(“Y”) - $year;
$month_diff = date(“m”) - $month;
$day_diff = date(“d”) - $day;
if […]
MJGUEST is a free professional guestbook using php mySQL
MJGUEST is a free professional guestbook, designed as hi-end solution for both personal homepages and corporate websites.
Thanks to a constant focus on research and innovation, every feature is pushed to the limit, day after day, to provide one of the most powerful and reliable […]
An attractive CSS based guestbook script using MySQL database
Micro guestbook is a MySQL based guestbook script with a CSS based attractive interface. It can store the name, date, message, location, web and email information of the visitor.
You can download it from the download section.
Screenshots:
Another Cool Free CMS: AIOCP
Version 1.3.018
www.tecnick.com Front Page
Admin Login
Username- admin
Password- 1234
Things you should know:
The demo of this system is a default installation.
Some admin features may have been disabled for security reasons.
The entire system is deleted and reinstalled every two hours.
We encourage you to take advantage of opensourceCMS and be the administrator of this software system. Add, create, […]
Free PHP Content Management System (CMS) : 1024
What is 1024?
1024 is a PHP, MySQL based Content Management System. 1024 is one of a few CMS’s leading the way with the implementation of the AJAX technology into all its areas. This includes dynamic adminstration and user interaction. 1024 offers you to ability to set up your own […]
welcome to free php resources page
welcome….
just test.. coming up soon…

