PHP (IP and ISP)

Hi all,

What’s wrong with this code in PHP:

<?php
if (getenv(“HTTP_X_FORWARDED_FOR”)){
$ip = getenv(“HTTP_X_FORWARDED_FOR”);
$client = gethostbyaddr($_SERVER[‘HTTP_X_FORWARDED_FOR’]);
} else {
$ip = getenv(“REMOTE_ADDR”);
$client = gethostbyaddr($_SERVER[‘REMOTE_ADDR’]);
}
$str = preg_split("/./", $client);
$i = count($str);
$x = $i - 1;
$n = $i - 2;
$isp = $str[$n] . “.” . $str[$x];
echo ‘<div>Tu IP es:<b style=“color:880000”> ‘.$ip.’</b> <br><br />
Tu ISP es: <b style=“color:000088”>’.$isp.’ </b></div>’;
?>

It works in a PHP file, but doesn’t work in Scriptcase blank application

Re: PHP (IP and ISP)

Can you post the error? I suspect it is a parsing error with the quotes, etc. Have you looked at the generated code to see what is happening?

Regards,
Scott.

Re: PHP (IP and ISP)

Hi Scott,

It doesn’t anything

Anyway now I need to put it in a PHP method

?is it posible?

Thanks

Re: PHP (IP and ISP)

Here are the steps that worked for me:

Created blank app
Created PHP method
Copied code to method

changed: (SC thinks [] is a global, add spaces)

$isp = $str[ $n ] . "." . $str[ $x ];

The spaces issue may not be a problem, but it was in older versions that I used.

Called method in onExecute
-Run app: displayed info

Regards,
Scott.

Re: PHP (IP and ISP)

Also note the if you run this on SC using ‘localhost’, your code gives an offset error on $n = $i - 2 (returns -1) due to your preg_split() call looking for a qualified name.

Regards,
Scott.

Re: PHP (IP and ISP)

in my opinion the best way is you check line by line…you should write code first line ,try to run and dont forget to active debug,if running well then you continue to write code on second line but if dont running well you should try to find out error on debug…so on.

regards
masbro