1 | <?php
|
---|
2 | ###############################################################################
|
---|
3 | ## Fancy Speed Test - Easily measure your upload and download speeds
|
---|
4 | ## Home Page: http://www.brandonchecketts.com/speedtest/
|
---|
5 | ## Author: Brandon Checketts
|
---|
6 | ## File: common.php
|
---|
7 | ## Version: 1.1
|
---|
8 | ## Date: 2006-02-06
|
---|
9 | ## Purpose: Common functions for this application
|
---|
10 | ###############################################################################
|
---|
11 |
|
---|
12 |
|
---|
13 | ## Read through the config file and assign items to the global $config variable
|
---|
14 | function ReadConfig($config_file) {
|
---|
15 | global $config;
|
---|
16 | $config = (object)array();
|
---|
17 | $lines = file($config_file);
|
---|
18 | foreach ($lines as $line_num => $line) {
|
---|
19 | $line = rtrim(preg_replace("/#.*/","",$line));
|
---|
20 | if (preg_match("/\[.*\]/", $line, $parts)) {
|
---|
21 | $section = $parts[0];
|
---|
22 | $section = preg_replace("/[\[\]]/","",$section);
|
---|
23 | $config->{$section} = (object)array();
|
---|
24 | } elseif (preg_match("/=/",$line)) {
|
---|
25 | list($var,$value) = explode('=',$line);
|
---|
26 | $var = preg_replace('/ $/','',$var);
|
---|
27 | $value = preg_replace('/^ +/','',$value);
|
---|
28 | $config->{$section}->{$var} = $value;
|
---|
29 | }
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | ## Write to log if debugging is on
|
---|
34 | function Debug($message) {
|
---|
35 | global $config;
|
---|
36 | if ($config->{'general'}->{'debug'}) {
|
---|
37 | BCLog($message);
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | ## Write to the log file
|
---|
42 | function BCLog($message) {
|
---|
43 | global $config;
|
---|
44 | $logfile = $config->{'general'}->{'logfile'};
|
---|
45 | if (! $logfile) {
|
---|
46 | return;
|
---|
47 | }
|
---|
48 | $timestamp = date("Y z H:i:s");
|
---|
49 |
|
---|
50 | $LOG=fopen($logfile,"a");
|
---|
51 | $string="$timestamp $message\n";
|
---|
52 | fwrite($LOG,$string);
|
---|
53 | fclose($LOG);
|
---|
54 | }
|
---|