Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP JSON

Featured Replies

It is probably because I am tired but I can't figure out the problem with my signature image stats update script, here is the faulting code:

//Nocache

header('Cache-Control: no-cache, must-revalidate');

header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

//Write time to file for run check

date_default_timezone_set('Europe/London');

$fh = fopen('lastrun.txt', 'w');

fwrite($fh, time());

fclose($fh);

//Get JSON feed

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,'http://www.lcpdfr.com/cops/usagestats/endpoint.php?variable=statistics&action=render&username=Sniper296');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$curl = curl_exec($ch);

curl_close($ch);

//JSON to array

$json = json_decode($curl, true);

//Save stats array to file

$fh1 = fopen('array.txt', 'w');

foreach($json as $key => $value) {

fwrite($fh1, substr($key, 1, strlen($key)) . ':' . $value . "\n");

}

fclose($fh1);

unset($value);

//echo $json[sPursuits];

It worked this afternoon but now it throws "Warning: Invalid argument supplied for foreach() in /signatue/lcpdfr/update.php on line 36"

You are using the WRONG right theme!

[ WIPs | Donate | 🌌 Join Mod Multiverse!]
Flashing LED lightbar in British configuration

  • Management Team

hmm, weird.

Try and replace

//Get JSON feed

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,'http://www.lcpdfr.com/cops/usagestats/endpoint.php?variable=statistics&action=render&username=Sniper296');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$curl = curl_exec($ch);

curl_close($ch);

with just

$curl = file_get_contents('http://www.lcpdfr.com/cops/usagestats/endpoint.php?variable=statistics&action=render&username=Sniper296');

Just incase curl is the issue.

  • Author

Nope, both file_get_contents and curl retrieve the same content:

{"sPursuits":417,"sSuspectsArrested":245,"sCitations":230,"sBackupUnits":656,"sEvidence":16,"sKilled":11,"sAccidents":131,"sNoose":30,"sHelis":40,"aLoadStatus":[4.33,4.33,4.52],"bStatus":true}

You are using the WRONG right theme!

[ WIPs | Donate | 🌌 Join Mod Multiverse!]
Flashing LED lightbar in British configuration

  • Management Team

I think I fixed the issue, looks like the page was sending the wrong content-type (don't ask me why that was effecting the string though :confused: )

This testing script seems to be working now:

<?php

$stuff = file_get_contents('http://www.lcpdfr.com/cops/usagestats/endpoint.php?variable=statistics&action=render&username=Sniper296');

var_dump($stuff);

$json = json_decode($stuff, true);

var_dump($json);

?>

  • Author

Yes, my original code is working again, on a side note I had to trick the forum using .htaccess into thinking the image is at

http://twoninersix.multigamemods.com/signatue/lcpdfr/stats.png

when it is at

http://twoninersix.multigamemods.com/signatue/lcpdfr/stats.php

to avoid

[#10210] You are not allowed to use that image extension on this board.

You are using the WRONG right theme!

[ WIPs | Donate | 🌌 Join Mod Multiverse!]
Flashing LED lightbar in British configuration

  • Management Team

Yes, my original code is working again, on a side note I had to trick the forum using .htaccess into thinking the image is at

http://twoninersix.multigamemods.com/signatue/lcpdfr/stats.png

when it is at

http://twoninersix.multigamemods.com/signatue/lcpdfr/stats.php

to avoid

[#10210] You are not allowed to use that image extension on this board.

Stupid IPB - awesome signature and awesome use of the API!

Uber late response, but one thing to note with json_decode() is that it has some native issues with some unicode/multibyte stuff, instead of even producing a proper error, it will just indeed, return null.

You can basically break your way around this with this lovely hackery (okay not really hackery) of code;

$json_obj = json_decode(mb_convert_encoding($stuff, 'UTF-8', mb_detect_encoding($stuff, 'UTF-8, ISO-8859-1', true)));




Might also be using the following at the start of things for 'modern' sake if anything;




declare(encoding='UTF-8');

mb_internal_encoding("UTF-8");

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Similar Content

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.