How to add simple php or java function result into page or block? I am writing a description of services provided. It is related to CGNAT. Would be good for reader to be displayed their external IP address. That could be done with simple function php code like:
<?php //whether ip is from share internet if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip_address = $_SERVER['HTTP_CLIENT_IP']; } //whether ip is from proxy elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } //whether ip is from remote address else { $ip_address = $_SERVER['REMOTE_ADDR']; } echo 'Your IP address is '; echo $ip_address; if (str_starts_with ($ip_address, '100')) { echo '. It starts with 81, that means you are behind CGNAT.'; } else echo '. It does not appear like starts with 100. To be sure, you can logon into your router and check internet connection status. '; ?>
It is working if a php file placed in pub directory and called directly, but not working if the code itself or attempt to call the file placed inside page or block, like:
<?php include 'ipaddress.php';?>
How it supposed to be done correctly? Also would appreciate more reliable code for spotting CGNAT.
HY there i can see your post and i must say
Java: Adding Java function results to a webpage requires a bit more complexity due to Java's server-side nature. Here's a simplified example using Java Servlets and JSP (JavaServer Pages): ADP Workforce
Thanks and regards