Simple PHP script - VMS problem [message #175819] |
Thu, 27 October 2011 14:39 |
Pygmalion
Messages: 2 Registered: October 2011
Karma: 0
|
Junior Member |
|
|
I have simple PHP counting script, that works perfectly under linux/
unix. It is called using counter.php?Identifier=introduction, than it
reads counter.txt, which looks like
index = 55
introduction = 5
animals = 4
increases introduction to 6 and writes counter.txt. When used in VMS,
it only writes down the first line
index = 55.
I guess the problem is in lines
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf("%s = %d\n", $Key, $Value);
fwrite($fp, $tmp);
}
which I think does not work properly in VMS. Any idea how to solve
the problem? The whole script is below.
<?php
// get environment
$query_string = getenv("QUERY_STRING");
// parse environment
// split query-string
if(strstr($query_string,"&"))
{$env_array = split("&", $query_string);}
else
{$env_array = split("&", $query_string);}
// split in key=value and convert %XX
while (list($key, $val) = each($env_array))
{
// split
list($name, $wert) = split("=", $val);
// replace %XX by character
$name = urldecode($name);
$wert = urldecode($wert);
// write to $cgivars
$CGIVars[$name] = $wert;
}
if ($CGIVars["Identifier"] <> "")
{
// read counter-file
if (file_exists("counter.txt"))
{
$fp = fopen("counter.txt", "rt");
while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg("([^ ]*) = *([0-9]*)", $Line, $tmp))
{
$CArr["$tmp[1]"] = $tmp[2];
}
}
// close file
fclose($fp);
// get counter
$Counter = $CArr[$CGIVars["Identifier"]];
$Counter += 1;
$CArr[$CGIVars["Identifier"]] = $Counter;
}
else
{
// the new counter is initialized with 1
$CArr[$CGIVars["Identifier"]] = 1;
$Counter = 1;
}
// write counter file
$fp = fopen("counter.txt", "wt");
// output array elements
reset($CArr);
while (list($Key, $Value) = each($CArr))
{
$tmp = sprintf("%s = %d\n", $Key, $Value);
fwrite($fp, $tmp);
}
// close file
fclose($fp);
$Counter = sprintf($Counter);
echo $Counter;
}
?>
|
|
|
Re: Simple PHP script - VMS problem [message #175820 is a reply to message #175819] |
Thu, 27 October 2011 14:49 |
Pygmalion
Messages: 2 Registered: October 2011
Karma: 0
|
Junior Member |
|
|
I just figure out that it might just as well be a read problem (reads
only first line or reads all lines as one):
while ($Line = fgets($fp, 999))
{
// split lines into identifier/counter
if (ereg("([^ ]*) = *([0-9]*)", $Line, $tmp))
{
$CArr["$tmp[1]"] = $tmp[2];
}
}
|
|
|
|