Files
http2pic/src/helpers.php
Chris 5df5a0ad7a
All checks were successful
Build Container / docker (push) Successful in 2m7s
added logging
2025-06-10 11:50:24 +02:00

35 lines
945 B
PHP
Executable File

<?php
function renderTemplate($templatename,$variables=[],$basepath=ROOT.'/src')
{
ob_start();
if(is_array($variables))
extract($variables);
if(file_exists($basepath.DS.'templates'.DS.$templatename.'.php'))
include($basepath.DS.'templates'.DS.$templatename.'.php');
else if(file_exists($basepath.DS.'templates'.DS.$templatename))
include($basepath.DS.'templates'.DS.$templatename);
$rendered = ob_get_contents();
ob_end_clean();
return $rendered;
}
function addToLog($data)
{
$fp = fopen(ROOT.DS.'logs'.DS.'app.log','a');
fwrite($fp,date("d.m.y H:i")."\t".$data."\n");
fclose($fp);
}
function getUserIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}