Sorry if the title is a bit confusing.
My results below indicate what is happening.
This question has become quite extensive, so I emphasize these two things here:
Check out my update below for a plausible reason.
Entire file: (see line 86) http://codepad.org/oIXaZZaB
Here's what happens:
I have this array that contains an integer count for each language code.
$downloads = [
'all' => [
'nl-BE' => 0,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
],
'unique' => [
'nl-BE' => 0,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
]
];
The key is obtained from the parameter $_GET['langCode'], always gets counted in the corresponding key $downloads['all'].
, $langCode. $langCode, $downloads['unique'].
:
$uniqueVisitors = [
'127.0.0.1' => [ 'en-UK' ]
];
if ($uniqueVisitors == null)
{
$uniqueVisitors = [
$ipNew => []
];
}
$countUnique = 1;
if (isset($uniqueVisitors[$ipNew]))
{
if (in_array($langCode, $uniqueVisitors[$ipNew]))
{
$countUnique = 0;
}
else $uniqueVisitors[$ipNew][] = $langCode;
}
else $uniqueVisitors[$ipNew] = [ $langCode ];
$downloads['all'][$langCode]++;
if ($countUnique)
{
$downloads['unique'][$langCode]++;
}
file_put_contents('data/unique-visitors.json', json_encode($uniqueVisitors));
file_put_contents('data/downloads.json', json_encode($downloads));
, script, , $langCode (. 'nl-NL')
'en-UK' 'en'.
'fr-FR' 'fr-BE'.
'nl-NL' 'nl-BE'.
, langCode - 0
, , .
, langCodes , , !
:
$downloads = [
'all' => [
'nl-BE' => 0,
'nl-NL' => 2,
'fr-BE' => 1,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
],
'unique' => [
'nl-BE' => 0,
'nl-NL' => 1,
'fr-BE' => 1,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
]
];
$uniqueVisitors = [
'127.0.0.1' => [ 'nl-NL', 'fr-BE' ]
];
$downloads = [
'all' => [
'nl-BE' => 0,
'nl-NL' => 2,
'fr-BE' => 1,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 1,
'en' => 1
],
'unique' => [
'nl-BE' => 0,
'nl-NL' => 1,
'fr-BE' => 1,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 1,
'en' => 1
]
];
$uniqueVisitors = [
'127.0.0.1' => [ 'nl-NL', 'fr-BE', 'en', 'en-UK' ]
];
: (. 86) http://codepad.org/oIXaZZaB
UPDATE:
file_put_contents() , , !
, , file_put_contents(), () , - .
?!
- ?
2:
json_encode() file_put_contents() -, " ", ($downloads):
Notice: Array to string conversion in /Applications/MAMP/htdocs/project/downloads/downloads.php on line 89
Notice: Array to string conversion in /Applications/MAMP/htdocs/project/downloads/downloads.php on line 90
Notice: Array to string conversion in /Applications/MAMP/htdocs/project/downloads/downloads.php on line 90
file_put_contents('data/unique-visitors.json', json_encode($uniqueVisitors));
file_put_contents('data/downloads.json', json_encode($downloads));
? .
3:
, JSON $downloads, .
file_put_contents() $downloads, . / file_put_contents, .
$downloads:
$downloads = [
'all' => [
'nl-BE' => 0,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
],
'unique' => [
'nl-BE' => 0,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
]
];
$_GET['langCode'] = 'nl-BE':
$downloads = [
'all' => [
'nl-BE' => 1,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
],
'unique' => [
'nl-BE' => 1,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
]
];
file_put_contents():
$downloads = [
'all' => [
'nl-BE' => 2,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
],
'unique' => [
'nl-BE' => 1,
'nl-NL' => 0,
'fr-BE' => 0,
'fr-FR' => 0,
'de-DE' => 0,
'it-IT' => 0,
'en-UK' => 0,
'en' => 0
]
];
, file_put_contents, $downloads script ( file_put_contents). file_get_contents .
4: ()
, Safari 7 .
Firefox Chrome script.
?
Htaccess:
htaccess.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)/?$ index.php?lang=$1 [QSA,NC,L]
</IfModule>