Re: Is This Code OK?
| From: | Joe Stump | Date: | Sat, 21 Oct 2000 20:02:28 +0000 |
| Subject: | Re: Is This Code OK? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21583@lists.php.net to get a copy of this message | ||
> > <?
> >
> > $file = '/tmp/data.txt';
> >
> > $fp = fopen($file,'r');
> > $value = fread($fp,filesize($file));
> > fclose($fp);
> >
> > $new_value = ($value + 1);
> >
> >
echo "\$hits = $new_value;" > $file;
> >
> > ?>
echo "<? \$hits = $new_value; ?>" > $file is a unix command that will echo
<? $hits = 2; ?> into a file - you can then include $file in a php script
and echo $hits out (2).
After the first time you done' have to read it in just echo $hits+1 into $file
to update $file.
--Joe
> >
> > Double check my syntax on the echo "\$hits = $new_value" >
> > $file;
> >
> > --Joe
> >
> >
> > On Sat, Oct 21, 2000 at 12:55:03PM +0500, iGuru wrote:
> > > Can anyone please check if the below mentioned code is correct or can be
> > > reduced further. I am trying to make a simple page counter with this
> code.
> > > Note that the data.txt file only contains the number '1' at startup.
> > >
> > > Can you please check if the below mentioned code is correct or can be
> > > reduced further. I am trying to make a simple page counter with this
> code.
> > > Note that the data.txt file only contains the number '1' at startup.
> > >
> > > <?php
> > > $file_loc = "data.txt";
> > >
> > > $oldfile = fopen($file_loc,"r");
> > > $file_contents = fread($oldfile,filesize($file_loc));
> > > $oldval = $file_contents;
> > > fclose($oldfile);
> > >
> > > $newfile = fopen($file_loc, "w+");
> > > echo $old;
> > > $old = fread($newfile, $newfile);
> > > $newval=$oldval+1;
> > > fwrite($newfile, "$newval");
> > > fclose($newfile);
> > > echo $newval;
> > > ?>
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > > For additional commands, e-mail: php-general-help@lists.php.net
> > > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> > /*****************************\
> > * Joe Stump *
> > * www.Care2.com *
> > * Office: 650.328.0198 *
> > * Extension: 122 *
> > \*****************************/
> > http://www.miester.org/Joe/Stump/Joe_Stump_resume.html
> >
> > -----BEGIN GEEK CODE BLOCK-----
> > Version: 3.12
> > GB/E/IT d- s++:++ a? C++++ UL++$ P+ L+++$ E----! W+++$
> > N+@ o? K? w---! O-@ M+@ V-! P(++) PE(+) Y+@ PGP+++@ t+@
> > 5? R-! tv@ b+ DI++@ D(++++) G++@ e+@ h@ r+! z(+++++**)!
> > ------END GEEK CODE BLOCK------
> >
/*****************************\
* Joe Stump *
* www.Care2.com *
* Office: 650.328.0198 *
* Extension: 122 *
\*****************************/
http://www.miester.org/Joe/Stump/Joe_Stump_resume.html
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GB/E/IT d- s++:++ a? C++++ UL++$ P+ L+++$ E----! W+++$
N+@ o? K? w---! O-@ M+@ V-! P(++) PE(+) Y+@ PGP+++@ t+@
5? R-! tv@ b+ DI++@ D(++++) G++@ e+@ h@ r+! z(+++++**)!
------END GEEK CODE BLOCK------