Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
Moderator: General Moderators
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Fri Jul 19, 2002 2:25 pm
I would like to introduce to the PHPDN forums...
PHP Tennis ! As seen on the
SitePoint Forums , the idea of the game is "serve" with a single script then "volley" with a revision of the "served" code, with some modifications.
The server must pick a piece of code from the
Zend Code Gallery to begin. The next person then makes a modification of this code according to the limits set at the beginning of the game (lines-per-edit, etc). And so on and so forth until either someone posts code with a fatal error or the time limit is up.
Editing posts constitutes disqualification.
The winner is the person who submitted the last piece of working code.
The full (rather long) list of rules can be found
here
____________________________________________________________
So here goes for the first match...
Sudden death (free for all)
Max lines per edit: 3
Time limit: None
Code:
http://zend.com/codex.php?id=29&single=1 Code: Select all
<?
$counter = "counter.txt";
function displayCounter($counter) {
$fp = fopen("$counter", "r");
$num = fread( $fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen("$counter", "w");
fwrite( $fa, $fpsoma, 100);
fclose($fa);
echo "<center><h1>Hit number $fpsoma</h1></center>";
}
displayCounter($counter);
?>Competitors step up!
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Fri Jul 19, 2002 3:28 pm
Awww, come on .. only 3 lines?? How about 5?
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Fri Jul 19, 2002 3:44 pm
Ummmm... no. Those are the rules for this game... Just add 3 lines, then someone else can add the other two. Or something...
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Fri Jul 19, 2002 8:52 pm
Okay, with a brief overview of the rules, I hope this satisfies them:
Code: Select all
<?
$counter = "counter.txt";
function displayCounter($counter, $prefix='', $suffix='')
{
if ( file_exists($counter) ) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
}
}
displayCounter($counter);
?>
Next =)
EricS
Forum Contributor
Posts: 183 Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga
Post
by EricS » Fri Jul 19, 2002 11:38 pm
Code: Select all
<?
$counter = "counter.txt";
function displayCounter($counter, $prefix='', $suffix='')
{
if ( file_exists($counter) ) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
}
else {
echo ("File not found.");
}
}
displayCounter($counter);
?>
EricS
Forum Contributor
Posts: 183 Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga
Post
by EricS » Sat Jul 20, 2002 12:10 am
I forgot to comment the above code per the rules, anyway, I just add a little code to display an error message upon not finding the file specified.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jul 20, 2002 5:29 am
Code: Select all
function displayCounter($counter, $prefix='', $suffix='')
{
if ( file_exists($counter) ) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE; // someone might want to check this
}
else {
echo ("File not found.");
return FALSE; // s.o
}
}
displayCounter($counter);
?>
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Sat Jul 20, 2002 10:33 am
Code: Select all
// open a file containing a list of already counted IP's and check that $ip is in the list
function checkUniqueVisitor($ip) {
}
function displayCounter($counter, $prefix='', $suffix='')
{
if ( file_exists($counter) ) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
}
else {
echo ("File not found.");
return FALSE;
}
}
displayCounter("counter.txt"); // pass the counter file
?>[/quote]
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Jul 20, 2002 11:43 am
Code: Select all
// open a file containing a list of already counted IP's and check that $ip is in the list
function checkUniqueVisitor($ip) {
$ip = getenv('REMOTE_ADDR');
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='')
{
if ( file_exists($counter) ) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
}
else {
echo ("File not found.");
return FALSE;
}
}
displayCounter("counter.txt"); // pass the counter file
?>
lol, i was going to start using mysql, but i decided it'd be better off to go flat file, to stay consistent
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Sat Jul 20, 2002 5:46 pm
Code: Select all
<?php
class Counter {
// open a file containing a list of already counted IP's and check that $ip is in the list
function checkUniqueVisitor($ip)
{
$ip = getenv('REMOTE_ADDR');
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='')
{
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
Counter::displayCounter("counter.txt"); //pass the counter file
?>Put it all in a class.
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Sat Jul 20, 2002 5:47 pm
Code: Select all
<?php
class Counter {
// open a file containing a list of already counted IP's and check that $ip is in the list
function checkUniqueVisitor($ip)
{
$ip = getenv('REMOTE_ADDR');
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='')
{
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
Counter::displayCounter("counter.txt"); //pass the counter file
?>Put it all in a class.
Posted again, used wrong tags
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jul 20, 2002 7:05 pm
Code: Select all
<?php
class Counter {
function checkUniqueVisitor($ip)
{
$ip = getenv('REMOTE_ADDR');
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='')
{
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
$oCounter = new Counter; // what is a class without an instance of it ;)
Counter::displayCounter("counter.txt"); //pass the counter file
?>
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Sat Jul 20, 2002 8:55 pm
Code: Select all
<?php
class Counter {
function Counter() { // what is a class without a constructor :-)
}
function checkUniqueVisitor($ip) {
$ip = getenv('REMOTE_ADDR');
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='') {
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
$oCounter = new Counter;
$oCounter->displayCounter("counter.txt"); // instantiated object calls the function
?>
hob_goblin
Forum Regular
Posts: 978 Joined: Sun Apr 28, 2002 9:53 pm
Contact:
Post
by hob_goblin » Sat Jul 20, 2002 11:23 pm
Code: Select all
<?php
class Counter {
function Counter() { // what is a class without a constructor :-)
}
function checkUniqueVisitor($ip) {
$ip = getenv('REMOTE_ADDR');
$arr = file("ips.txt");
if(in_array($ip,$arr){
return FALSE; }
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='') {
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
$oCounter = new Counter;
$oCounter->displayCounter("counter.txt"); // instantiated object calls the function
?>
continued with the IP checking
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Jul 21, 2002 5:41 am
Code: Select all
<?php
class Counter {
var m_id; // instances should store something
function Counter() {
m_id = uniqid(); // empty constructors aren't that nice
}
function checkUniqueVisitor($ip) {
$ip = getenv('REMOTE_ADDR');
$arr = file("ips.txt");
if(in_array($ip,$arr){
return FALSE; }
$_fp = fopen("ips.txt", 'a+');
fclose("$_fp");
}
function displayCounter($counter, $prefix='', $suffix='') {
if (file_exists($counter)) {
$fp = fopen($counter, 'r');
$num = fread($fp, 100);
$fpsoma = ($num + 1);
fclose($fp);
$fa = fopen($counter, 'w');
fwrite($fa, $fpsoma, 100);
fclose($fa);
echo $prefix.$fpsoma.$suffix;
return TRUE;
} else {
echo ("File not found.");
return FALSE;
}
}
}
$oCounter = new Counter;
$oCounter->displayCounter("counter.txt");
?>