FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Simple PHP script - VMS problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Simple PHP script - VMS problem [message #175819] Thu, 27 October 2011 14:39 Go to previous message
Pygmalion is currently offline  Pygmalion
Messages: 2
Registered: October 2011
Karma:
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,"&amp;"))
{$env_array = split("&amp;", $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;
}
?>
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: My first PHP Script...
Next Topic: ZIP file download
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 02:13:03 GMT 2024

Total time taken to generate the page: 0.04605 seconds