Title: I Heart Code Fails...Not
Author: LeeDavis
Category: CODING
Published: 2017-02-24 10:35:02
Clicks: 120

I Heart Code Fails...Not
This was a code fail that I'd seen initially in a search for an open-source "coming soon" page with an admin panel. It's an attractively interfaced codebase in both front and back;

Application Front Side

Application Back Side

The functionality is admittedly original as the subscriber information is handled in a matter more analogous to XML information storage than the flat-file process. Even for all its' sophistication (and it's really gem-like in this respect), the main need of the application: admin needs to survey subscriber list on designated page, fails horribly. The subscriber list fails to be output for display on the subscribers.php page where it SHOULD reside;

And even though the processing of the application works well enough so that the information captured from the front-side email input form is written to the subscribers.txt.php page;

the information isn't getting through in the admin panel AT ALL. For my forensic investigation, I relied on my server error_log file generated in the folder where the coding munge actually happened (and what I love about live server dynamics). The consistency of error caused by the authors' incorrect variable initialization ($subscribers = array();), thus;

$filecontent = file_get_contents( '../' . $config['subscribers_file'] );
$subscribers = explode("\r\n", $filecontent);
$subscribers = array_slice($subscribers, 3); // remove first 3 lines of file (php comments)
$subscribers = array_values( array_filter($subscribers) );

is not the same as;

$subscribers = file_get_contents( '../' . $config['subscribers_file'] );
$filecontent = explode("\r\n", $subscribers);
$subscribers = array_slice($filecontent, 3); // remove first 3 lines of file (php comments)
$subscribers = array_values( array_filter($filecontent) );