[FX.php List] Capturing IP for a choice calc

DC dan.cynosure at dbmscan.com
Wed Mar 1 12:08:58 MST 2006


ah... that is a puzzle.

then there's got to be a proxy in there somewhere... which is another 
reason i suggested why you might see a LAN address in this field. i'm 
not sure of the details on how the REMOTE_ADDR server variable is 
populated, but it may be that you have a funky PHP setup that doesn't 
give the PHP script access to the outside (real) IP of the machine.

here's what i see when i do host on the domain:
sandbox.sjcpl.org has address 66.205.162.50

so from the outside world your sandbox does have a real IP, but to the 
PHP script it has a LAN IP.

try this:
<?php

echo php_info();
$v=get_defined_vars();
print_r('<pre>');
print_r($v);
print_r('</pre>');
?>

and poke through it to see if you can see any outside IP.

if there's nothing there, you may be able to run something like this:

<?php
echo shell_exec('curl -s http://checkip.dyndns.org/ | cut -d":" -f2 | 
cut -d"<" -f1 | cut -d" " -f2');
?>

note that you must have the ability to run shell scripts for this to 
work AND you must have curl installed (installed by default on mac OSX).

if you can't do that then try it like this:

<?php
$my_ip= file_get_contents('http://checkip.dyndns.org/');
echo $my_ip;
//parse the IP address using preg_match() or other functions
?>

cheers,
dan

Peter Bates had written:
> No, I'm not running my browser on the same mac as the webserver. I  just 
> copied and pasted your snippet into a new blank document, saved  it onto 
> my sandbox and then used the browser on my mac to access the  page. I've 
> even tried it on another Mac that has an outside address.  both inside 
> and outside access yields the same: 10.0.0.50. That's the  address of 
> the webserver.
> 
> Give it a try yourself: http://sandbox.sjcpl.org/showip.php
> 
> Vinnie's code produces the same: http://sandbox.sjcpl.org/showip2.php
> 
> 
> Peter
> 
> On Mar 1, 2006, at 12:52 PM, DC wrote:
> 
>> if you are getting your server's IP from that variable, then your  
>> server is making the request for the script.
>>
>> perhaps you are testing the script while you are on the server? is  
>> your browser running on the machine with the webserver?
>>
>> or you may be using that variable at a stage in a secondary script  
>> that has been kicked off by a remote request. you would see your  own 
>> server's IP if you wrote a PHP file that called another PHP  file 
>> through an http mechanism like so:
>>
>> <?php
>> // main calling script
>> $output_of_sub_file = file_get_contents("http://example.com/ file.php");
>> echo $output_of_sub_file;
>> ?>
>>
>> <?php
>> //sub-file file.php
>> echo $_SERVER['REMOTE_ADDR'];
>> ?>
>>
>> Peter Bates had written:
>>
>>> Thanks Andy and Dan,
>>> This gives me the IP of my server, not the users IP. Is that the  
>>> way  it is supposed to be, or am I missing something?
>>> Peter
>>> On Mar 1, 2006, at 10:23 AM, Andy Gaunt wrote:
>>>
>>>> You may also want to build an array of IP addresses, possibly  from  
>>>> a small
>>>> table in FMPro or if a small number, you could just create an  
>>>> array  in a php
>>>> file that you include in your page.
>>>>
>>>> Then you can query the IP (using the code below posted by Dan)  and  
>>>> see if it
>>>> exists in the array. If it does, display the info, otherwise   
>>>> display your
>>>> message.
>>>>
>>>> Andy Gaunt
>>>> T: 407.810.4722
>>>> andy at fmpug.com
>>>> http://www.fmpug.com
>>>>
>>>> Recipient of FileMaker's 2005 "Mad Dog" Public Relations Award
>>>>
>>>> For chapter locations, dates & times please visit the website at
>>>> http://www.fmpug.com If you can make it to a meeting, please RSVP at
>>>> http://www.fmpug.com/rsvp.php
>>>>
>>>> -----Original Message-----
>>>> From: fx.php_list-bounces at mail.iviking.org
>>>> [mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of DC
>>>> Sent: Wednesday, March 01, 2006 10:18 AM
>>>> To: FX.php Discussion List
>>>> Subject: Re: [FX.php List] Capturing IP for a choice calc
>>>>
>>>> check this for general information about PHP's predefined variables:
>>>>
>>>> http://us2.php.net/manual/en/  
>>>> reserved.variables.php#reserved.variables.serve
>>>> r
>>>>
>>>> in short... you want to use this variable in PHP:
>>>> <?php
>>>> echo $_SERVER['REMOTE_ADDR'];
>>>> ?>
>>>>
>>>> cheers,
>>>> dan
>>>>
>>>> Peter Bates had written:
>>>>
>>>>> I'm building a solution that contains some copyrighted material  
>>>>> on  our
>>>>> website. We have permission to share the copyrighted material  
>>>>> with  our
>>>>> patrons while they are in one of our building, but not if they are
>>>>> accessing the site from outside the building. I'm assuming that  I  
>>>>> need
>>>>> to capture the requesting IP address before the data is  displayed  
>>>>> that
>>>>> basically does the following:
>>>>>
>>>>> If IP = Our in-house IP range         <!-- We have our own in-house
>>>>> network, inside and outside DNS servers, web server, etc. -->
>>>>>    Show data from field "x"             <!-- This would be  actually a
>>>>> link that is stored in a FMP field. -->
>>>>> Else
>>>>>    Show "We're sorry, but due to copyright restrictions, this   
>>>>> material
>>>>> is only available in one of our library branches"   <!-- This   
>>>>> would be
>>>>> displayed in place of the data from  field "x" -->
>>>>> End If
>>>>>
>>>>> As I am still floundering around using FileMaker Pro with FX.php, I
>>>>> would deeply appreciate any help that could point me into the right
>>>>> direction to code this.
>>>>>
>>>>> Mac OS X Server 10.4x, FileMaker Server Advanced 8x, PHP 4.x
>>>>>
>>>>> Thanks,
>>>>> Peter
>>>>>
>>>>> Peter Bates
>>>>> Microcomputer Network Specialist
>>>>> Automated Services
>>>>> St. Joseph County Public Library
>>>>> 304 S. Main St.
>>>>> South Bend, IN  46601
>>>>> voice: (574) 282-4610
>>>>> fax: (574) 282-4662
>>>>> e-mail: p.bates at sjcpl.org <mailto:p.bates at sjcpl.org>
>>>>> www:  http:/www.libraryforlife.org
>>>>> library catalog:
>>>>> http://www.libraryforlife.org/onlinecatalog/onlinecatalog.html
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------------------------------------- 
>>>>> -- ---
>>>>>
>>>>> _______________________________________________
>>>>> FX.php_List mailing list
>>>>> FX.php_List at mail.iviking.org
>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>>
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>>
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
> 
> 
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
> 


More information about the FX.php_List mailing list