Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Mar 2011 15:30:08 -0500
From:      Ryan Coleman <editor@d3photography.com>
To:        Gary Kline <kline@thought.org>
Cc:        FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG>
Subject:   Re: why does this simple counter fail?
Message-ID:  <B818092D-A7EC-417D-94C0-5BAB5138EC0E@d3photography.com>
In-Reply-To: <20110324185340.GD15209@thought.org>
References:  <20110323164504.GA25317@thought.org> <B322245C-7251-45B7-A29A-D9DAC9F54AAC@d3photography.com> <20110324185340.GD15209@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Here's a quick and dirty option...
FIRST make sure your permissions on the folder you want to write the =
countfile to is either at RWX to all or is owned by the Apache run user =
(PHP by default runs under the Apache Service user).

I ran this in file test.php on my server. Give it a whirl.

<?
$dir =3D "/path/to/stored/counts/";
$dir =3D $_SERVER['DOCUMENT_ROOT']."test/"; //This was to test in "test" =
directory in VHOST root folder.
$file =3D $_SERVER['PHP_SELF'].".txt"; //this keeps it from being loaded =
in browser as a php-executable
#$file =3D urlencode($_SERVER['REQUEST_URI']).".txt"
	// 	This option if uncommented will make =
/file/path/filename.php?that=3Dthis&five=3D5=20
	//	turn into =
"%2Ffile%2Fpath%2Ffilename.php%3Fthat%3Dthis%26five%3D5". Not pretty but =
functional.

if(!is_file($dir.$file)) {
	$dump =3D fopen($dir.$file, "x+");
	fclose($dump);
}
//Read current value
$fp_read =3D fopen($dir.$file, "r");
$count =3D fread($fp_read, filesize($dir.$file)+1);
fclose($fp_read);

//Convert count to integer
$new_count =3D ((int)$count);
//Increase count by 1
$new_count++;


//Reopen to write new value
$fp =3D fopen($dir.$file, "w+");
fwrite($fp, $new_count);
fclose($fp);

echo "A count was added. It was #".$new_count;
?>

On Mar 24, 2011, at 1:53 PM, Gary Kline wrote:

> On Wed, Mar 23, 2011 at 11:47:16AM -0500, Ryan Coleman wrote:
>> Do you have an error for it?
>>=20
>> If not... add after the first <?
>> error_reporting(9);
>>=20
>> And see what it reports.
>>=20
>> --
>> Ryan
>> PHP dev.
>>=20
>=20
> 	save the bandwidth...
>=20
>=20
> Ok, i added the error_reporting line to both scripts.  No change
> from the count.php, and the same output as prev from my script that
> tries to pick a random entry from some 70 quotes.  here is what the
> randomquote.php scipt output onto the home page:
>=20
>=20
>=20
>=20
> Last updated:
> 17 February, 2011
>=20
> echo "err-9 line below:\n"; $number-1){ // If ran out of quotes,
> start again! $num=3D0; } if (file_exists($directory.$quotecountfile))
> { $nu =3D fopen ($directory.$quotecountfile, "w"); fputs($nu,$num); }
> else { die("Cant Find $quotecountfile"); } } ?>
>=20
>=20
> Note that i added the echo line just now. =20
>=20
> Having a quote isn't as meaningful as giving users the latest
> pagecount.  That still fails without any errors. =20
>=20
> gary
>=20
>=20




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B818092D-A7EC-417D-94C0-5BAB5138EC0E>