/
load.php
114 lines (92 loc) · 3.44 KB
/
load.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?
/**
* Package Name: Stripe Pad
* File Description: Include this file anywhere to load all environment
*
* @author Beto Ayesa <beto.phpninja@gmail.com>
* @version 1.0.0
* @package StripePad
* @license GPL3
* @link https://github.com/natzar/stripe-pad
*
*/
# Include configuration file
require_once dirname(__FILE__).'/config.php';
# Defaults
ini_set('log_errors', 1);
ini_set('error_log', APP_PATH.APP_NAME."-errors.log");
error_reporting(DEBUG_MODE ? E_ALL : E_NONE);
ini_set('display_errors', DEBUG_MODE ? 1 : 0);
ini_set('display_startup_errors', DEBUG_MODE ? 1 : 0);
mb_internal_encoding(INTERNAL_ENCODING);
date_default_timezone_set(TIMEZONE);
setlocale (LC_ALL, LOCALE_LANG);
setlocale(LC_TIME, LOCALE_TIME);
# Session
if (PHP_SESSION_ACTIVE != session_status() and !headers_sent()){
ini_set('session.cookie_lifetime', 3600 * 24 );
ini_set('session.gc_maxlifetime', 3600 * 24 );
session_set_cookie_params(3600 * 24);
session_start();
}
# Include composer autoload
if (is_file(dirname(__FILE__)."/vendor/autoload.php")) require(dirname(__FILE__)."/vendor/autoload.php");
# Include base classes
include_once CORE_PATH."ModelBase.php";
include_once CORE_PATH.'SPDO.php';
include_once CORE_PATH.'View.php';
# Register fatal errors
register_shutdown_function(function() {
$error = error_get_last();
if ($error !== NULL) {
// Clear the output buffer to prevent previous output
//ob_clean();
// Custom error handling logic
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
$error_msg = date("d/m/Y H:i:s")." ".$errstr." [".$errno."]"." File: ".$errfile." // Line: ".$errline." ";
file_put_contents(ROOT_PATH.APP_SLUG."-errors.log", $error_msg, FILE_APPEND);
// echo $error_msg . '<br>';
include "app/themes/".APP_THEME."/errors/error.php";
} else {
// Flush the buffer if there's no error
//ob_end_flush();
flush();
}
});
# Capture any error to file
set_error_handler(function($errno, $errstr, $errfile, $errline ){
$error_msg = Date("d/m/Y H:i:s")." ".$errstr." [". $errno."]"." File: ". $errfile. " // Linea: ".$errline." ";
@file_put_contents(ROOT_PATH.APP_SLUG."-errors.log", $error_msg);
if (DEBUG_MODE){
include "app/themes/".APP_THEME."/errors/error.php";
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
});
# include all models from app dynamically
foreach (glob(dirname(__FILE__)."/app/models/*.php") as $filename)
{
include $filename;
}
# Include Modules
include dirname(__FILE__)."/modules/requestBlocker/bot-blocker.php";
include dirname(__FILE__)."/modules/emailValidator/emailValidator.php";
# Helper functions
function isLocalhost() {
// List of common localhost IP addresses
$localhostIPs = array(
'127.0.0.1',
'::1',
);
// Check if we are running from the command line
if (php_sapi_name() === 'cli' || defined('STDIN')) {
// In CLI, assume localhost environment or implement additional logic as needed
return true;
}
// Check if the server IP or remote IP is in the list of localhost IPs
$serverAddr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
$remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
return in_array($serverAddr, $localhostIPs) || in_array($remoteAddr, $localhostIPs);
}