PHP Help !


okay - i'm trying bottom of this. when preview
pages on local testing server, online.php file (which back-end
coding display number of visitors on website) getting loads of
errors; however, when uploaded _remote_ server -
works fine.

here online.php file:
*******

<?php

$ip = $_server['remote_addr'];
$time = time();
$minutes = 3;
$found = 0;
$users = 0;
$user = "";

$tmpdata = $_server['document_root']."/vonline/data";

if (!is_file("$tmpdata/online.txt"))
{
$s = fopen("$tmpdata/online.txt","w");
fclose($s);
chmod("$tmpdata/online.txt",0666);
}

$f = fopen("$tmpdata/online.txt","r+");
flock($f,2);

while (!feof($f))
{
$user[] = chop(fgets($f,65536));
}

fseek($f,0,seek_set);
ftruncate($f,0);

foreach ($user $line)
{
list($savedip,$savedtime) = split("\|",$line);
if ($savedip == $ip) {$savedtime = $time;$found = 1;}
if ($time < $savedtime + ($minutes * 60))
{
fputs($f,"$savedip|$savedtime\n");
$users = $users + 1;
}
}

if ($found == 0)
{
fputs($f,"$ip|$time\n");
$users = $users + 1;
}

fclose ($f);

$draw = '<span style="font-size: 11px">number of active
visitors: </span>';
$formatted = '<span style="font-size: 11px; color: #22ae22; font-weight:
bold">';
$formattedend = '</span>';
echo $draw;
echo $formatted;
echo $users;
echo $formattedend;
?>

*******

i'm getting following errors on local testing:

warning: fopen(c:/program files/apache
group/apache2/htdocs/vonline/data/online.txt) [function.fopen]: failed
open stream: no such file or directory in c:\program files\apache
group\apache2\htdocs\ad\adnew\vonline\online.php on line 14

warning: fclose(): supplied argument not valid stream resource in
c:\program files\apache group\apache2\htdocs\ad\adnew\vonline\online.php on
line 15

warning: chmod() [function.chmod]: no such file or directory in c:\program
files\apache group\apache2\htdocs\ad\adnew\vonline\online.php on line 16

warning: fopen(c:/program files/apache
group/apache2/htdocs/vonline/data/online.txt) [function.fopen]: failed
open stream: no such file or directory in c:\program files\apache
group\apache2\htdocs\ad\adnew\vonline\online.php on line 19

warning: flock() expects parameter 1 resource, boolean given in
c:\program files\apache group\apache2\htdocs\ad\adnew\vonline\online.php on
line 20

and these 2 errors keep getting repeated on , on , on again
(never-ending):

warning: feof(): supplied argument not valid stream resource in
c:\program files\apache group\apache2\htdocs\ad\adnew\vonline\online.php on
line 22

warning: fgets(): supplied argument not valid stream resource in
c:\program files\apache group\apache2\htdocs\ad\adnew\vonline\online.php on
line 24

i'm stressing on - great relief!

--
shane h
shane@nospamavenuedesigners.com
http://www.avenuedesigners.com


shane h wrote:
> okay - i'm trying bottom of this. when preview
> pages on local testing server, online.php file (which back-end
> coding display number of visitors on website) getting loads of
> errors; however, when uploaded _remote_ server -
> works fine.

the following section causing problems.

> if (!is_file("$tmpdata/online.txt"))
> {
> $s = fopen("$tmpdata/online.txt","w");
> fclose($s);
> chmod("$tmpdata/online.txt",0666);
> }

it's designed test whether online.txt exists, , if not, create
it. however, whoever created script made fundamental
mistake: is_file() checks whether existing resource file.
check whether file exists, need use file_exists(). also, chmod
is meaningless on windows server. rewrite section this:

if (!file_exists("$tmpdata/online.txt")) {
touch("$tmpdata/online.txt");
}

--
david powers
author, "foundation php dreamweaver 8" (friends of ed)
author, "foundation php 5 flash" (friends of ed)
http://foundationphp.com/


More discussions in Dreamweaver support forum


adobe

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62