<?php
define('FILE_READ_MODE', 0644);
define('FILE_WRITE_MODE', 0666);
define('DIR_READ_MODE', 0755);
define('DIR_WRITE_MODE', 0777);
define('FOPEN_READ', 'rb');
define('FOPEN_READ_WRITE', 'r+b');
define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
define('FOPEN_WRITE_CREATE', 'ab');
define('FOPEN_READ_WRITE_CREATE', 'a+b');
define('FOPEN_WRITE_CREATE_STRICT', 'xb');
define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
define('CHARSET', 'UTF-8');
define('CHARSET_NAMES', 'utf8');
define('CHARSET_COLLATION', 'utf8_general_ci');
//////////////////////////////////////////////////////////////////////////////
if (isset($_SERVER['HTTP_HOST'])) {
if (
(strpos($_SERVER['HTTP_HOST'], '.') === FALSE) || //from my computer
(substr($_SERVER['HTTP_HOST'], 0, 8) === '192.168.') || //from private ip address
($_SERVER['HTTP_HOST'] === '127.0.0.1') || //from localhost
($_SERVER['HTTP_HOST'] === '10.0.2.2') //from android emulator
) {
$user = "root";
$pass = "";
$db = "center_test";
}
}
$base_url = 'http://localhost/';
if (isset($_SERVER['HTTP_HOST'])) {
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://' . $_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
$base_path = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
date_default_timezone_set('UTC');
//////////////////////////////////////////////////////////////////////////////
if (!function_exists('escape_date')) {
function escape_date($str) {
$timestamp = strtotime($str);
return date("Y-m-d H:i:s", $timestamp);
}
}
if (!function_exists('utf8_header')) {
function utf8_header($type = 'text/html') {
header('Content-Type: ' . $type . '; charset=utf-8');
}
}
// ---------------------------------------------------------------------------
if (!function_exists('server_var')) {
function server_var($id) {
return isset($_SERVER[$id]) ? $_SERVER[$id] : '';
}
}
if (!function_exists('is_post')) {
function is_post() {
return server_var('REQUEST_METHOD') == 'POST';
}
}
if (!function_exists('is_get')) {
function is_get() {
return server_var('REQUEST_METHOD') == 'GET';
}
}
// ---------------------------------------------------------------------------
if (!function_exists('debug_log')) {
function debug_log($msg) {
$filepath = 'log-' . date('Y-m-d') . '.php';
$message = (' - ' . date('Y-m-d H:i:s') . ' --> ' . $msg . "\n");
if (!$fp = @fopen($filepath, FOPEN_WRITE_CREATE)) {
return FALSE;
}
flock($fp, LOCK_EX);
fwrite($fp, $message);
flock($fp, LOCK_UN);
fclose($fp);
@chmod($filepath, FILE_WRITE_MODE);
}
}
if (!function_exists('escape_str')) {
function escape_str($str, $like = FALSE) {
if (is_array($str)) {
foreach ($str as $key => $val) {
$str[$key] = escape_str($val, $like);
}
return $str;
}
if (function_exists('mysql_escape_string')) {
$str = mysql_escape_string($str);
} else {
$str = addslashes($str);
}
// escape LIKE condition wildcards
if ($like === TRUE) {
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
}
}
if (!function_exists('html_escape')) {
function html_escape($var) {
if (is_array($var)) {
return array_map('html_escape', $var);
} else {
return htmlspecialchars($var, ENT_QUOTES, CHARSET);
}
}
}
No comments:
Post a Comment