cancel
Showing results for 
Search instead for 
Did you mean: 

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?

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.

1 REPLY 1

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

 

  1. 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

  1. Create a Java Servlet: Write a Java Servlet that performs the desired function and stores the result in a request attribute.

Thanks and regards