How to add simple php or java function result into page or block?
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:
//whether ip is from share internet
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
//whether ip is from proxy
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
//whether ip is from remote address
$ip_address = $_SERVER['REMOTE_ADDR'];
echo 'Your IP address is ';
if (str_starts_with ($ip_address, '100'))
echo '. It starts with 81, that means you are behind CGNAT.';
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.
Re: How to add simple php or java function result into page or block?
HY there i can see your post and i must say
Server Configuration: Ensure your server is set up to process PHP files. The file should have a .php extension, and you need a PHP-capable web server (like Apache with PHP module enabled).
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
Create a Java Servlet: Write a Java Servlet that performs the desired function and stores the result in a request attribute.