resolve some errors in php logic, like strlen with str containing space that is interpreted as array instead of string
This commit is contained in:
28
plug/map_prof/utils/mp_console_log.php
Normal file
28
plug/map_prof/utils/mp_console_log.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// https://stackify.com/how-to-log-to-console-in-php/
|
||||
|
||||
function mp_log($output) {
|
||||
$type = gettype($output);
|
||||
if ($type == 'object')
|
||||
$output = serialize($output);
|
||||
$time = date('H:i');
|
||||
$file = '/var/www/html/wp-debug.log';
|
||||
file_put_contents($file, $time . " " . $output . "\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
function mp_console_log($output) {
|
||||
$js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
|
||||
$js_code = '<script>' . $js_code . '</script>';
|
||||
echo $js_code;
|
||||
}
|
||||
|
||||
// function mp_console_log($output, $with_script_tags = true) {
|
||||
// $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) .
|
||||
// ');';
|
||||
// if ($with_script_tags) {
|
||||
// $js_code = '<script>' . $js_code . '</script>';
|
||||
// }
|
||||
// echo $js_code;
|
||||
// }
|
||||
|
||||
?>
|
||||
18
plug/map_prof/utils/mp_get_ip.php
Normal file
18
plug/map_prof/utils/mp_get_ip.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
function mp_get_ip() {
|
||||
$external_ip = "";
|
||||
// curl with php :
|
||||
// https://www.php.net/manual/en/function.curl-init.php
|
||||
$ch = curl_init('https://ifconfig.me/ip');
|
||||
// CURLOPT_RETURNTRANSFER is set to true, which means that cURL should return the response from the HTTP request as a string, rather than printing it to the screen
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$external_ip = curl_exec($ch);
|
||||
//mp_console_log("ip:");
|
||||
//mp_console_log($external_ip);
|
||||
curl_close($ch);
|
||||
|
||||
return $external_ip;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user