if(!function_exists('pre_var_dump')) {
function pre_var_dump() {
$dark_mode = false;
$back_trace = debug_backtrace();
$last = end($back_trace);
$back_trace_array = array();
foreach($back_trace as $each_trace) {
$back_trace_array[] = @$each_trace['file'] . ' ' . @$each_trace['line'];
}
//Apparently hsl is the coolest color system
$h = rand(0, 359);
$s = rand(0, 99);
$l = '';
$color = "white";
if ($dark_mode) {
$l = '15';
$color = 'white';
} else {
$l = '70';
$color = 'black';
}
$container_id = "pre_var_dump-container-" . $h . $s;
$is_cli = php_sapi_name() == 'cli';
if ($is_cli) {
echo PHP_EOL . ">------------------ START: ".date("Y-m-d H:i:s")."----------------------<";
} else {
echo "<pre style='background-color:hsl({$h}deg, {$s}%, {$l}%); color: {$color}; padding: 10px; border-radius: 5px; font-size: 14px; line-height: 20px; z-index: 99999; position: relative;'><details>";
}
$step = 0;
foreach($back_trace_array as $i => $each_trace) {
if ($is_cli) {
echo PHP_EOL . "[{$step}][{$each_trace}]";
} else {
if ($i == 0) {
echo "<summary>[{$step}][{$each_trace}]</summary>";
} elseif ($i === 1) {
echo "[{$step}][{$each_trace}]";
} else {
echo PHP_EOL . "[{$step}][{$each_trace}]";
}
}
$step++;
}
if (!$is_cli) {
echo "</details>".PHP_EOL;
} else {
echo PHP_EOL;
}
if (!$is_cli) {
echo "<button type='button' onclick='document.querySelector(`#{$container_id}`).style.display == `none` ? document.querySelector(`#{$container_id}`).style.display = `block` : document.querySelector(`#{$container_id}`).style.display = `none`;'>";
echo "Collapse/Expand - Collapse/Expand - Collapse/Expand - Collapse/Expand";
echo "</button>";
}
if (!$is_cli) {
echo "<div id='{$container_id}'>";
foreach (func_get_args() as $param) {
var_dump($param);
}
echo "</div>";
echo "</pre>";
} else {
foreach (func_get_args() as $param) {
var_dump($param);
echo PHP_EOL;
}
echo PHP_EOL . ">------------------ END: ".date("Y-m-d H:i:s")."----------------------<" . PHP_EOL;
}
}
}
Regex for lines does not contain xxxx
^((?!xxxx).)*$
CURL
$url = 'https://xxxxxxxx';
$ch = curl_init();
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer YOUR_API_KEY";
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_array));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
CURL function
if(!function_exists("curl"))
{
function curl ($url='', $jsonpayload=array(), $payload=array(), $method='GET', $headers=array(), $options=array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if (!empty($options['ignore_ssl_errors'])) {
if ($options['ignore_ssl_errors']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
}
//curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
if (strtoupper($method) == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
} elseif (strtoupper($method) != 'GET') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
}
if (!empty($payload)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
}
if(!empty($jsonpayload))
{
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($jsonpayload));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
//pre_var_dump(curl_getinfo($ch, CURLINFO_HTTP_CODE));
curl_close ($ch);
return $server_output;
}
}
CURL vervobse
function curl_verbose ($url='', $jsonpayload=array(), $payload=array(), $method='GET', $headers=array(), $options=array()) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if (!empty($options['ignore_ssl_errors'])) {
if ($options['ignore_ssl_errors']) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
}
curl_setopt($ch, CURLOPT_VERBOSE, true);
$streamVerboseHandle = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
//curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
if (strtoupper($method) == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
} elseif (strtoupper($method) != 'GET') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));
}
if (!empty($payload)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
}
if(!empty($jsonpayload))
{
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($jsonpayload));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
//pre_var_dump(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if ($server_output === FALSE) {
printf("cUrl error (#%d): %s<br>\n",
curl_errno($ch),
htmlspecialchars(curl_error($ch)))
;
}
rewind($streamVerboseHandle);
$verboseLog = stream_get_contents($streamVerboseHandle);
echo "cUrl verbose information:\n",
"<pre>", htmlspecialchars($verboseLog), "</pre>\n";
curl_close ($ch);
return $server_output;
}
if(!function_exists('mysqli_array_insert_single_row')) {
function mysqli_array_insert_single_row($conn, $table_name, $data_array, $return_query = false) {
if ($conn) {
foreach ($data_array as $key => $value) {
if (empty($value) && $value !== 0 && $value !== '') {
$data_array[$key] = 'NULL';
} else {
$data_array[$key] = "'" . mysqli_real_escape_string($conn, $value) . "'";
}
}
$insert_keys = array_keys($data_array);
$insert_keys = implode("`,`", $insert_keys);
$insert_values = implode(",", $data_array);
$table_name = str_replace(".","`.`",$table_name);
$insert_sql = "INSERT INTO `{$table_name}` (`{$insert_keys}`) VALUES " . PHP_EOL . "({$insert_values});";
if ($return_query) {
return $insert_sql;
} else {
$insert_query = mysqli_query($conn, $insert_sql);
}
if ($insert_query) {
return mysqli_insert_id($conn);
} else {
return $insert_query;
}
} else {
return false;
}
}
}
if (!function_exists("mysqli_array_update_single_row")) {
function mysqli_array_update_single_row($conn = null, $table_name = null, $data_array = nul, $pk_col = '', $pk_col_val = '', $return_sql = false) {
// error_reporting(-1);
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
}
$table_name = str_replace(".","`.`",$table_name);
if(empty($data_array)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(empty($pk_col)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$pk_col = mysqli_real_escape_string($conn, $pk_col);
}
if(empty($pk_col_val)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$pk_col_val = mysqli_real_escape_string($conn, $pk_col_val);
}
$update_array = array();
foreach($data_array as $index => $each_data_row) {
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
// $on_duplicate_key_update_array[] = "`{$index}` = VALUES(`{$index}`)";
$update_array[] = "`{$index}` = {$data_array[$index]}";
}
$update_string = implode(", ", $update_array);
$update_sql = "UPDATE `{$table_name}` SET {$update_string} WHERE `{$pk_col}` = '{$pk_col_val}';";
if ($return_sql) {
return $update_sql;
}
$update_query = mysqli_query($conn, $update_sql);
if ($update_query) {
return $pk_col_val;
} else {
return mysqli_error($conn);
}
}
}
if (!function_exists("delete_single_row")) {
function delete_single_row ($conn = null, $table_name = null, $data_array = array(), $pk_col = '', $pk_val = '', $return_sql = false, $param = array()) {
// error_reporting(-1);
if (!empty($pk_col) && !empty($pk_val)) {
if (!isset($data_array[$pk_col])) {
$data_array[$pk_col] = $pk_val;
}
}
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$table_name = str_replace("`", "", $table_name);
if (stripos($table_name, ".") !== false) {
$table_name = explode(".", $table_name);
foreach ($table_name as &$each_part) {
$each_part = mysqli_real_escape_string($conn, $each_part);
}
$table_name = implode("`.`", $table_name);
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
}
}
if(empty($data_array)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
$delete_where = '1=1';
// $data_array_raw = $data_array;
if (isset($data_array['id'])) {
$pk_col = 'id';
$pk_val = $data_array['id'];
} else {
$table_name_esc = mysqli_real_escape_string($conn, $table_name);
$pk_sql = "SHOW KEYS FROM `{$table_name_esc}` WHERE Key_name = 'PRIMARY';";
$pk_query = mysqli_query($conn, $pk_sql);
$pk = mysqli_fetch_assoc($pk_query);
$pk_col = $pk['Column_name'];
// $pk_val = $data_array[$pk_col];
}
foreach($data_array as $index => $each_data_row) {
$index = mysqli_real_escape_string($conn, $index);
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
if (strpos($data_array[$index], "'") !== false) {
$delete_where .= " AND `$index` LIKE $data_array[$index]";
} else {
$delete_where .= " AND `$index` = $data_array[$index]";
}
}
$data_old_sql = "SELECT * FROM `{$table_name}` WHERE {$delete_where};";
$data_old_query = mysqli_query($conn, $data_old_sql);
$data_old = mysqli_fetch_assoc($data_old_query);
$delete_sql = "DELETE FROM `{$table_name}` WHERE {$delete_where};";
if ($return_sql) {
return $delete_sql;
}
$delete_query = mysqli_query($conn, $delete_sql);
if ($delete_query) {
$table_name = str_replace("`.`", ".", $table_name);
_db_change($conn, 'DELETE', $table_name, $pk_col, $data_old[$pk_col], null, $data_old, $param);
return true;
} else {
$err = mysqli_error($conn);
// $error_data = array();
// $error_data['query'] = mysqli_real_escape_string($conn, $update_sql);
// $error_data['error'] = mysqli_real_escape_string($conn, $err);
// $error_log_insert_sql = "INSERT INTO `error_log` (query, error) VALUES ('{$error_data['query']}', '{$error_data['error']}');";
// $error_log_insert_query = mysqli_query($conn, $error_log_insert_sql);
return $err;
}
}
}
if (!function_exists("insert_or_update_single_row")) {
function insert_or_update_single_row($conn = null, $table_name = null, $data_array = nul, $return_sql = false) {
// error_reporting(-1);
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
}
$table_name = str_replace(".","`.`",$table_name);
if(empty($data_array)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
$on_duplicate_key_update_array = array();
foreach($data_array as $index => $each_data_row) {
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
$on_duplicate_key_update_array[] = "`{$index}` = VALUES(`{$index}`)";
// $on_duplicate_key_update_array[] = "`{$index}` = VALUES({$data_array[$index]})";
}
$insert_cols = array_keys($data_array);
$insert_cols = implode("`,`", $insert_cols);
$insert_data = implode(",", $data_array);
$on_duplicate_key_update_string = implode(", ", $on_duplicate_key_update_array);
$insert_sql = "INSERT INTO `{$table_name}` (`$insert_cols`) VALUES ($insert_data) ON DUPLICATE KEY UPDATE {$on_duplicate_key_update_string};";
if ($return_sql) {
return $insert_sql;
}
$insert_query = mysqli_query($conn, $insert_sql);
if ($insert_query) {
return mysqli_insert_id($conn);
} else {
return mysqli_error($conn);
}
}
}
New db functions
if (!function_exists("_get_database_change_name")) {
function _get_database_change_name($conn = null, $year = '', $schema = '')
{
if (empty($year)) {
$year = date("Y");
}
$database_change_name = "base_database_change_{$year}";
if (!empty($schema)) {
$schema = mysqli_real_escape_string($conn, str_replace("`", "", $schema));
$check_for_exists = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '{$database_change_name}' AND TABLE_SCHEMA LIKE '{$schema}';";
} else {
$check_for_exists = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '{$database_change_name}';";
}
$check_for_exists = mysqli_query($conn, $check_for_exists);
$check_for_exists = mysqli_num_rows($check_for_exists);
if (empty($schema)) {
$tbl_name = $database_change_name;
$tbl_name_quoted = "`{$database_change_name}`";
} else {
$tbl_name = $schema . "." . $database_change_name;
$tbl_name_quoted = "`{$schema}`.`{$database_change_name}`";
}
if ($check_for_exists < 1) {
//create the db change table
$sql = <<<SQL
CREATE TABLE {$tbl_name_quoted} (
`id` INT(15) NOT NULL AUTO_INCREMENT,
`query_type` SET('INSERT','UPDATE','DELETE') NOT NULL,
`database_table` VARCHAR(128) NOT NULL,
`data_id` VARCHAR(100) DEFAULT NULL,
`field_name` VARCHAR(100) DEFAULT NULL,
`field_data_old` TEXT DEFAULT NULL,
`field_data_new` TEXT DEFAULT NULL,
`ip` VARCHAR(15) NOT NULL,
`file_name` TEXT NOT NULL,
`user` INT(10) NOT NULL,
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
`delflag` INT(1) DEFAULT NULL,
`memid` INT(15) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `cmbidx` (`query_type`,`data_id`,`database_table`) USING BTREE,
KEY `cmb2idx` (`query_type`,`data_id`,`database_table`,`field_name`) USING BTREE,
KEY `cmb3idx` (`query_type`,`field_data_old`(100),`database_table`,`field_name`) USING BTREE,
KEY `tbl` (`database_table`) USING BTREE,
KEY `dataidx` (`data_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
SQL;
$query = mysqli_query($conn, $sql);
}
return $tbl_name;
}
}
if (!function_exists("_insert_single_row_no_db_change")) {
function _insert_single_row_no_db_change($conn = null, $table_name = null, $data_array = null, $return_sql = false) {
// error_reporting(-1);
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
}
if(empty($data_array)) {
pre_var_dump('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
foreach($data_array as $index => $each_data_row) {
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
}
$insert_cols = array_keys($data_array);
$insert_cols = implode("`,`", $insert_cols);
$insert_data = implode(",", $data_array);
// $on_duplicate_key_update_string = implode(", ", $on_duplicate_key_update_array);
$table_name = str_replace(".","`.`",$table_name);
$insert_sql = "INSERT INTO `{$table_name}` (`$insert_cols`) VALUES ($insert_data);";
if ($return_sql) {
return $insert_sql;
}
try
{
$insert_query = mysqli_query($conn, $insert_sql);
}
catch (\Exception $e)
{
return $e->getMessage();
}
if ($insert_query) {
$inserted_id = mysqli_insert_id($conn);
return $inserted_id;
} else {
$err = mysqli_error($conn);
// $error_data = array();
// $error_data['query'] = mysqli_real_escape_string($conn, $insert_sql);
// $error_data['error'] = mysqli_real_escape_string($conn, $err);
// $error_log_insert_sql = "INSERT INTO `error_log` (query, error) VALUES ('{$error_data['query']}', '{$error_data['error']}');";
// $error_log_insert_query = mysqli_query($conn, $error_log_insert_sql);
return $err;
}
}
}
if (!function_exists("_db_change")) {
function _db_change ($conn = null, $query_type = '', $table_name = '', $pk_col = null, $pk_val = null, $data_array = array(), $field_data_old = array(), $param = array()) {
$sch = explode(".",$table_name);
if(count($sch)==1) { $sch[1] = $sch[0]; $sch[0] = ""; }
$database_change_name = _get_database_change_name($conn, null, $sch[0]);
if (isset($_SESSION)) {
if (!empty($_SESSION['remote_addr'])) {
$ip = $_SESSION['remote_addr'];
}
}
if (empty($ip)) {
if( ! empty($_SERVER['HTTP_CLIENT_IP'])) {
// ip from share internet
$ip = @$_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// ip pass from proxy
$ip = @$_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
$ip = @$_SERVER['REMOTE_ADDR'];
} else {
$ip = '';
}
}
if (isset($_SESSION)) {
// pre_var_dump($_SESSION);
// die(PHP_EOL.__FILE__.__LINE__.PHP_EOL);
if (empty($user)) {
if (!empty($_SESSION['user'])) {
$user = $_SESSION['user'];
}
}
}
if (!empty($param['user'])) {
$user = $param['user'];
}
if (empty($user)) {
$user = 0;
}
$bt = debug_backtrace();
$file = array();
foreach ($bt as $caller) {
$file[] = 'File:' . $caller['file'] . ' Line:' . $caller['line'];
}
$file = array_slice($file, 0, 4);
$file = implode(PHP_EOL, $file);
if ($query_type == 'DELETE') {
if (!empty($field_data_old)) {
foreach ($field_data_old as $col_name => $each_col) {
$database_change_arr = array();
$database_change_arr['query_type'] = $query_type;
$database_change_arr['database_table'] = $table_name;
$database_change_arr['data_id'] = $pk_val;
$database_change_arr['field_name'] = $col_name;
$database_change_arr['field_data_old'] = @$field_data_old[$database_change_arr['field_name']];
$database_change_arr['field_data_new'] = null;
$database_change_arr['ip'] = $ip;
$database_change_arr['file_name'] = $file;
$database_change_arr['user'] = $user;
$database_change_arr['date'] = date("Y-m-d\TH:i:s");
$database_change_arr['delflag'] = 1;
_insert_single_row_no_db_change($conn, $database_change_name, $database_change_arr);
}
}
} else {
foreach ($data_array as $col_name => $each_col) {
$database_change_arr = array();
$database_change_arr['field_name'] = $col_name;
$database_change_arr['field_data_old'] = @$field_data_old[$database_change_arr['field_name']];
$database_change_arr['field_data_new'] = @$each_col;
if ((string)$database_change_arr['field_data_new'] != (string)$database_change_arr['field_data_old']) {
$database_change_arr['query_type'] = $query_type;
$database_change_arr['database_table'] = $table_name;
$database_change_arr['data_id'] = $pk_val;
// $database_change_arr['field_data_old'] = @$field_data_old[$database_change_arr['field_name']];
// $database_change_arr['field_data_new'] = @$each_col;
$database_change_arr['ip'] = $ip;
$database_change_arr['file_name'] = $file;
$database_change_arr['user'] = $user;
$database_change_arr['date'] = date("Y-m-d\TH:i:s");
_insert_single_row_no_db_change($conn, $database_change_name, $database_change_arr);
}
}
}
}
}
if (!function_exists("insert_single_row")) {
function insert_single_row($conn = null, $table_name = null, $data_array = array(), $return_sql = false, $param = array()) {
$table_name_esc = mysqli_real_escape_string($conn, $table_name);
$sch = explode(".",$table_name);
if(count($sch)==1) { $sch[1] = $sch[0]; $sch[0] = ""; }
$sch[0] = mysqli_real_escape_string($conn, $sch[0]);
$sch[1] = mysqli_real_escape_string($conn, $sch[1]);
if (empty($sch[0])) {
$structure_sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '{$sch[1]}';";
} else {
$structure_sql = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '{$sch[1]}' AND TABLE_SCHEMA LIKE {'$sch[0]}';";
}
$structure_query = mysqli_query($conn, $structure_sql);
$structure = array();
$keys = array_keys($data_array);
$keys = array_flip($keys);
$keys = json_encode($keys);
$keys = strtolower($keys);
$keys = json_decode($keys, true);
$to_insert = array();
foreach($data_array as $key => $value) {
$key = strtolower($key);
$data_array[$key] = $value;
}
while ($row = mysqli_fetch_assoc($structure_query)) {
$col_name_lower = strtolower($row['COLUMN_NAME']);
if (!isset($keys[$col_name_lower])) {
} else {
$to_insert[$row['COLUMN_NAME']] = $data_array[$col_name_lower];
}
}
$inserted_res = _insert_single_row_no_db_change($conn, $table_name, $to_insert, $return_sql);
if (is_numeric($inserted_res)) {
$to_insert['id'] = $inserted_res;
// pre_var_dump($inserted_res);
// die(PHP_EOL.__FILE__.__LINE__.PHP_EOL);
_db_change($conn, 'INSERT', $table_name, 'id', $inserted_res, $to_insert, array(), $param);
} else {
}
return $inserted_res;
}
}
if (!function_exists("update_single_row")) {
function update_single_row($conn = null, $table_name = null, $data_array = array(), $pk_col = '', $pk_val = '', $return_sql = false, $param = array()) {
// error_reporting(-1);
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(empty($data_array)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
$data_array_raw = $data_array;
$t_name_exp = explode(".", $table_name);
if (sizeof($t_name_exp) == 2) {
$t_name_exp[0] = mysqli_real_escape_string($conn, $t_name_exp[0]);
$t_name_exp[1] = mysqli_real_escape_string($conn, $t_name_exp[1]);
$table_name = "`{$t_name_exp[0]}`.`{$t_name_exp[1]}`";
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
$table_name = "`{$table_name}`";
}
//$table_name = mysqli_real_escape_string($conn, $table_name);
$pk_col = mysqli_real_escape_string($conn, $pk_col);
$pk_val = mysqli_real_escape_string($conn, $pk_val);
$field_data_old_sql = "SELECT * FROM {$table_name} WHERE `{$pk_col}` = '{$pk_val}';";
$field_data_old_query = mysqli_query($conn, $field_data_old_sql);
$field_data_old = mysqli_fetch_assoc($field_data_old_query);
$update_arr = array();
if ($field_data_old === null || $field_data_old_query === false) {
echo "update_single_row() FAILED. SQL:[{$field_data_old_sql}] @ " . __FILE__.__LINE__.PHP_EOL;
return false;
}
foreach($data_array as $index => $each_data_row) {
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if (!array_key_exists($index, $field_data_old)) {
// pre_var_dump($index);
continue;
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
if ($data_array[$index] == "''") {
$data_array[$index] = 'null';
}
$update_arr[] = " `{$index}` = $data_array[$index] ";
}
// pre_var_dump($field_data_old);
// pre_var_dump($data_array);
$update_str = implode(",", $update_arr);
$update_sql = "UPDATE {$table_name} SET {$update_str} WHERE `{$pk_col}` = '{$pk_val}';";
// pre_var_dump($update_sql);
if ($return_sql) {
return $update_sql;
}
try
{
$update_query = mysqli_query($conn, $update_sql);
}
catch (\Exception $e)
{
return $e->getMessage();
}
if ($update_query) {
_db_change($conn, 'UPDATE', $table_name, $pk_col, $pk_val, $data_array_raw, $field_data_old, $param);
return $pk_val;
} else {
$err = mysqli_error($conn);
// $error_data = array();
// $error_data['query'] = mysqli_real_escape_string($conn, $update_sql);
// $error_data['error'] = mysqli_real_escape_string($conn, $err);
// $error_log_insert_sql = "INSERT INTO `error_log` (query, error) VALUES ('{$error_data['query']}', '{$error_data['error']}');";
// $error_log_insert_query = mysqli_query($conn, $error_log_insert_sql);
return $err;
}
}
}
if (!function_exists("delete_single_row")) {
function delete_single_row ($conn = null, $table_name = null, $data_array = array(), $pk_col = '', $pk_val = '', $return_sql = false, $param = array()) {
// error_reporting(-1);
if (!empty($pk_col) && !empty($pk_val)) {
if (!isset($data_array[$pk_col])) {
$data_array[$pk_col] = $pk_val;
}
}
if(empty($table_name)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
} else {
$table_name = str_replace("`", "", $table_name);
if (stripos($table_name, ".") !== false) {
$table_name = explode(".", $table_name);
foreach ($table_name as &$each_part) {
$each_part = mysqli_real_escape_string($conn, $each_part);
}
$table_name = implode("`.`", $table_name);
} else {
$table_name = mysqli_real_escape_string($conn, $table_name);
}
}
if(empty($data_array)) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
if(!$conn) {
echo('Error @ ' . __FILE__.__LINE__);
return false;
}
$delete_where = '1=1';
// $data_array_raw = $data_array;
if (isset($data_array['id'])) {
$pk_col = 'id';
$pk_val = $data_array['id'];
} else {
$table_name_esc = mysqli_real_escape_string($conn, $table_name);
$pk_sql = "SHOW KEYS FROM `{$table_name_esc}` WHERE Key_name = 'PRIMARY';";
$pk_query = mysqli_query($conn, $pk_sql);
$pk = mysqli_fetch_assoc($pk_query);
$pk_col = $pk['Column_name'];
// $pk_val = $data_array[$pk_col];
}
foreach($data_array as $index => $each_data_row) {
$index = mysqli_real_escape_string($conn, $index);
if (is_array($each_data_row)) {
if (empty($each_data_row)) {
$each_data_row = null;
} else {
$each_data_row = json_encode($each_data_row);
}
}
if($each_data_row === null || strtolower($each_data_row) == 'null') {
$data_array[$index] = 'null';
} else if(strtolower($each_data_row) == 'current_timestamp') {
$data_array[$index] = 'CURRENT_TIMESTAMP';
} else if($each_data_row === array()) {
$data_array[$index] = 'null';
} else {
$data_array[$index] = "'" . mysqli_real_escape_string($conn, $each_data_row) . "'";
}
if (strpos($data_array[$index], "'") !== false) {
$delete_where .= " AND `$index` LIKE $data_array[$index]";
} else {
$delete_where .= " AND `$index` = $data_array[$index]";
}
}
$field_data_old_sql = "SELECT * FROM `{$table_name}` WHERE {$delete_where};";
$field_data_old_query = mysqli_query($conn, $field_data_old_sql);
$field_data_old = mysqli_fetch_assoc($field_data_old_query);
$delete_sql = "DELETE FROM `{$table_name}` WHERE {$delete_where};";
if ($return_sql) {
return $delete_sql;
}
$delete_query = mysqli_query($conn, $delete_sql);
if ($delete_query) {
$table_name = str_replace("`.`", ".", $table_name);
_db_change($conn, 'DELETE', $table_name, $pk_col, $field_data_old[$pk_col], null, $field_data_old, $param);
return true;
} else {
$err = mysqli_error($conn);
// $error_data = array();
// $error_data['query'] = mysqli_real_escape_string($conn, $update_sql);
// $error_data['error'] = mysqli_real_escape_string($conn, $err);
// $error_log_insert_sql = "INSERT INTO `error_log` (query, error) VALUES ('{$error_data['query']}', '{$error_data['error']}');";
// $error_log_insert_query = mysqli_query($conn, $error_log_insert_sql);
return $err;
}
}
}
function array_to_csv($path, $data_array) {
$headers = implode('","', array_keys(reset($data_array)));
$headers = '"' . $headers . '"';
file_put_contents($path, $headers);
foreach ($data_array as $each_row) {
$each_row_text = implode('","', $each_row);
$each_row_text = PHP_EOL . '"' . $each_row_text . '"';
file_put_contents($path, $each_row_text, FILE_APPEND);
}
return true;
}
function csv_to_array ($path = '') {
$rows = array_map('str_getcsv', file($path));
$header = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = array_combine($header, $row);
}
return $csv;
}
$document_root = !empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '/home/exampleacc/public_html';
$document_root = !empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : explode("public_html", __DIR__)[0] . 'public_html';
$logpath = $document_root . "/LOGNAME.log";
file_put_contents($logpath, PHP_EOL . PHP_EOL . __FILE__ . __LINE__ . ' @ [' . date('Y-m-d H:i:s') . '] ' . PHP_EOL . var_export($ticket, true) . PHP_EOL . '----------------------------------------------', FILE_APPEND);
$document_root = !empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : explode("public_html", __DIR__)[0] . 'public_html';
$logpath = $document_root . "/../".__FUNCTION__.".log";
$__profiler_time = time();
file_put_contents($logpath, PHP_EOL . PHP_EOL . __FILE__ . __LINE__ . ' @ [' . date('Y-m-d H:i:s') . '] ' . PHP_EOL . (time() - $__profiler_time) . PHP_EOL . '----------------------------------------------', FILE_APPEND);$__profiler_time = time();
Chrome server timing api
// begining of the function
$server_timing = array();
$end = microtime(true);
// put this line at strategic points. after the line you suspect is causing the slowness.
$dur = (microtime(true) - $end) * 1000; $server_timing[] = 'Line-' . __LINE__ . ";dur=" . $dur; $end = microtime(true);
// end of profiling, before return or die.
$timing_str = implode(", ", $server_timing);
header("Server-Timing: {$timing_str}");
$wsdl_url = "https://path/to/a/wsdl";
$client = new SoapClient($wsdl_url, array('cache_wsdl' => WSDL_CACHE_NONE));
$post_vars = array();
$response = $client->{$function_name}($post_vars);
If someone encounters the interesting problem in which PHP can connect to a MSSQL server from the command line but not when running as an Apache module: SELinux prevents Apache (and therefore all Apache modules) from making remote connections by default.
This solved the problem in CentOS:
# setsebool -P httpd_can_network_connect=1
Sublime sftp-config common ignores
"ignore_regexes": [
"\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
"sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
"\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini",
"\\.pdf", "\\.doc", "\\.xls", "\\.docx", "\\.xlsx", "\\.csv", "\\.txt", "\\.xml", "\\.msg",
"\\.mp4", "\\.mov",
"\\.jpg","\\.jpeg","\\.jpe","\\.jif","\\.jfif","\\.jfi","\\.jp2","\\.j2k","\\.jpf","\\.jpx","\\.jpm","\\.mj2","\\.jxr","\\.hdp","\\.wdp","\\.gif","\\.raw","\\.webp","\\.png","\\.apng","\\.mng","\\.tiff","\\.tif","\\.svg","\\.svgz","\\.pdf","\\.xbm","\\.bmp","\\.dib","\\.ico","\\.3dm","\\.max",
"\\.bak", "\\.zip", "\\.rar", "\\.7z", "\\.tar", "\\.exe", "\\.sql",
"error_log", "\\.log",
"\\.SUBLIME-(PROJECT|WORKSPACE)", "SFTP-CONFIG(-ALT\\D?)?\\.JSON",
"SFTP-SETTINGS\\.JSON", "/VENV/", "\\.SVN/", "\\.HG/", "\\.GIT/",
"\\.BZR", "_DARCS", "CVS", "\\.DS_STORE", "THUMBS\\.DB", "DESKTOP\\.INI",
"\\.PDF", "\\.DOC", "\\.XLS", "\\.DOCX", "\\.XLSX", "\\.CSV", "\\.TXT", "\\.XML", "\\.MSG",
"\\.MP4", "\\.MOV",
"\\.JPG","\\.JPEG","\\.JPE","\\.JIF","\\.JFIF","\\.JFI","\\.JP2","\\.J2K","\\.JPF","\\.JPX","\\.JPM","\\.MJ2","\\.JXR","\\.HDP","\\.WDP","\\.GIF","\\.RAW","\\.WEBP","\\.PNG","\\.APNG","\\.MNG","\\.TIFF","\\.TIF","\\.SVG","\\.SVGZ","\\.PDF","\\.XBM","\\.BMP","\\.DIB","\\.ICO","\\.3DM","\\.MAX",
"\\.BAK", "\\.ZIP", "\\.RAR", "\\.7Z", "\\.TAR", "\\.EXE", "\\.SQL",
"ERROR_LOG", "\\.LOG"
],
GIT ignore for PHP projects
.gitignore
Fix broken serialized string - fix string counts
function fix_str_length($matches) {
$string = $matches[2];
$right_length = strlen($string);
return 's:' . $right_length . ':"' . $string . '";';
}
function fix_serialized($string) {
if ( !preg_match('/^[aOs]:/', $string) ) return $string;
if ( @unserialize($string) !== false ) return $string;
$string = preg_replace("%\n%", "", $string);
$unlikely_occured_string = "]]]``|``[[[";
$data = preg_replace('%";%', $unlikely_occured_string, $string);
$tab = explode($unlikely_occured_string, $data);
$new_data = '';
foreach ($tab as $line) {
$new_data .= preg_replace_callback('%\bs:(\d+):"(.*)%', 'fix_str_length', $line);
}
return $new_data;
}
TMCR_MC_IM_BT
$corruptedSerialization = file_get_contents("serialized_string.txt");
$repairedSerialization = (string)fix_serialized($corruptedSerialization);
Strict Australian Mobile Numbers Regex
^(?:\+?61|0)4 ?(?:(?:[01] ?[0-9]|2 ?[0-57-9]|3 ?[1-9]|4 ?[7-9]|5 ?[018]) ?[0-9]|3 ?0 ?[0-5])(?: ?[0-9]){5}$
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$res = file_get_contents("https://some-random-url", false, stream_context_create($arrContextOptions));
if (stripos($_SERVER['HTTP_X_FORWARDED_FOR'], gethostbyname('office.bonntech.com.au')) !== false) {
}
Regex to find lines dont end with simicolon(;)
[.]*[^\;\{\}\(\)]\s*$
Output buffer output
for ($i=0; $i < 9999999999; $i++) {
ob_start();
var_dump($i);
ob_end_flush();
sleep(1);
}
rsync with special ssh port
rsync -avz -e "ssh -p 882" root@103.12.11.:/path/to/copy/public_html /local/path/above_public_html
search and replace on server
find ./ -type f -print0 | xargs -0 sed -i 's#search.term.com#replace_with.term.com#g'
MAC manually add private key pw to keychain
ssh-add -K
SQL SERVER show blocking with query
SELECT
D.text SQLStatement,
A.Session_ID SPID,
A.program_name,
ISNULL(B.status,A.status) Status,
A.login_name Login,
A.host_name HostName,
C.BlkBy,
DB_NAME(B.Database_ID) DBName,
B.command,
ISNULL(B.cpu_time, A.cpu_time) CPUTime,
ISNULL((B.reads + B.writes),(A.reads + A.writes)) DiskIO,
A.last_request_start_time LastBatch
FROM
sys.dm_exec_sessions A
LEFT JOIN
sys.dm_exec_requests B
ON A.session_id = B.session_id
LEFT JOIN
(
SELECT
A.request_session_id SPID,
B.blocking_session_id BlkBy
FROM sys.dm_tran_locks as A
INNER JOIN sys.dm_os_waiting_tasks as B
ON A.lock_owner_address = B.resource_address
) C
ON A.Session_ID = C.SPID
OUTER APPLY sys.dm_exec_sql_text(sql_handle) D
WHERE ISNULL(B.status,A.status) NOT IN ('background', 'sleeping');
Virtualmin PHP executable path
/opt/rh/rh-php72/root/usr/bin/php
Switch php version Virtualmin command line style
virtualmin modify-web --domain domain.com.au --php-version 7.2
Codeigniter 4 remove index.php from URL
/home/account/public_html/.htaccess
# Disable directory browsing
#Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
# Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
Prestashop class override clean up files
/public_html/var/cache/dev/class_index.php
/public_html/var/cache/prod/class_index.php
Fix dir/file permissions
find /home/example_account/banana -type d -exec chmod 755 {} \;
find /home/example_account/banana -type f -exec chmod 644 {} \;
Prestashop database delete all products and categories
########################
prestashop database delete all products and categories
########################
# BACKUP YOUR DATABASE #
########################
#
# This script truncates the product, carts, images table and all linked tables with dependent data.
#
# "*" indicates a Primary Key
#
# @author Ajax Zheng
# @website aaron.fun
# @copyright 2023 AjaxZ
#
########################
# BACKUP YOUR DATABASE #
########################
#Categories
DELETE FROM ps_category WHERE id_category > 2;
DELETE FROM ps_category_lang WHERE id_category > 2;
DELETE FROM ps_category_shop WHERE id_category > 2;
TRUNCATE ps_category_group;
TRUNCATE ps_category_product;
# All these tables have an id_product primary key [or should have!]
TRUNCATE TABLE ps_product; # *id_product id_supplier id_manufacturer id_tax_rules_group id_category_default id_color_default
TRUNCATE TABLE ps_product_shop;
TRUNCATE TABLE ps_product_attachment; # *id_product *id_attachment
TRUNCATE TABLE ps_product_country_tax; # id_product id_country id_tax
TRUNCATE TABLE ps_product_group_reduction_cache; # *id_product *id_group
TRUNCATE TABLE ps_product_lang; # *id_product *id_lang
TRUNCATE TABLE ps_product_sale; # *id_product
TRUNCATE TABLE ps_product_tag; # *id_product *id_tag
TRUNCATE TABLE ps_category_product; # id_product id_category
TRUNCATE TABLE ps_compare_product; # id_product *id_compare_product id_guest id_customer
TRUNCATE TABLE ps_feature_product; # *id_product *id_feature
TRUNCATE TABLE ps_search_index; # *id_product *id_word
TRUNCATE TABLE ps_specific_price; # id_product *id_specific_price
TRUNCATE TABLE ps_specific_price_priority; # *id_product *id_specific_price_priority
# This one is special, links product to product
TRUNCATE TABLE ps_accessory; # id_product_1 id_product_2
# Packs
TRUNCATE TABLE ps_pack; # *id_product_pack *id_product_item
# All these tables have an id_attachment primary key
TRUNCATE TABLE ps_attachment; # *id_attachment
TRUNCATE TABLE ps_attachment_lang; # *id_attachment *id_lang
# All these tables have an id_attribute primary key
TRUNCATE TABLE ps_attribute; # *id_attribute id_attribute
TRUNCATE TABLE ps_attribute_lang; # *id_attribute *id_lang
# All these tables have an id_attribute_group primary key
TRUNCATE TABLE ps_attribute_group; # *id_attribute_group
TRUNCATE TABLE ps_attribute_group_lang; # *id_attribute_group *id_lang
# All these tables have an id_attribute_impact primary key
TRUNCATE TABLE ps_attribute_impact; # *id_attribute_impact id_product id_attribute
# All these tables have an id_feature or id_feature_value key
TRUNCATE TABLE ps_feature; # *id_feature
TRUNCATE TABLE ps_feature_lang; # *id_feature *id_lang
TRUNCATE TABLE ps_feature_value; # *id_feature_value id_feature
TRUNCATE TABLE ps_feature_value_lang; # *id_feature_value *id_lang
TRUNCATE TABLE ps_feature_shop;
# All these tables have an id_customization_field key
TRUNCATE TABLE ps_customization_field; # *id_customization_field id_product
TRUNCATE TABLE ps_customization_field_lang; # *id_customization_field *id_lang
# All these tables have an id_image primary key [or should have!]
TRUNCATE TABLE ps_image; # *id_image id_product
TRUNCATE TABLE ps_image_lang; # id_image id_lang
# All these tables have an id_product_attribute primary key
TRUNCATE TABLE ps_product_attribute; # *id_product_attribute id_product
TRUNCATE TABLE ps_product_attribute_combination; # *id_product_attribute *id_attribute
TRUNCATE TABLE ps_product_attribute_image; # *id_product_attribute *id_image
# All these tables have an id_product_download primary key
TRUNCATE TABLE ps_product_download; # *id_product_download id_product
# All these tables have an id_word primary key
TRUNCATE TABLE ps_search_word; # *id_word id_lang
# All these tables have an id_tag primary key
# TRUNCATE TABLE ps_tag
# Empty carts
TRUNCATE TABLE ps_cart; # *id_cart ...
TRUNCATE TABLE ps_cart_discount; # id_cart
TRUNCATE TABLE ps_cart_product; # id_cart id_product id_product_attribute
TRUNCATE TABLE ps_customization; # *id_cart *id_customization *id_product
TRUNCATE TABLE ps_customized_data; # *id_customization (see above)
# Delete Scenes
TRUNCATE TABLE ps_scene; # *id_scene
TRUNCATE TABLE ps_scene_category; # *id_scene *id_category
TRUNCATE TABLE ps_scene_lang; # *id_scene *id_lang
TRUNCATE TABLE ps_scene_products; # *id_scene *id_product *x_axis *y_axis
# Delete stock movements
TRUNCATE TABLE ps_stock_mvt; # *id_stock_mvt id_product ...
#module data
TRUNCATE TABLE ps_quotes;
TRUNCATE TABLE ps_quotes_products;
TRUNCATE TABLE ps_fmm_quote_userdata;
TRUNCATE TABLE ps_wishlist;
TRUNCATE TABLE ps_wishlist_product;
TRUNCATE TABLE ps_wishlist_product_cart;
Display top 10 largest files/directories
du -hsx * | sort -rh | head -10
Search and extract .tar files
tar -tzf test.tar.gz | grep File_name.php
tar -zxvf test.tar.gz <./path/to/file/ copy output from above. starts from ./public_html normally>