Jump to content

Archived

This topic is now archived and is closed to further replies.

Lockit

Remote Addr Local Testing

Recommended Posts

Hello I was wondering how would I get $_SERVER['REMOTE_ADDR'] to work with local testing?

Whenever I run the script at the host computer it always returned the address of the router, but if done remotely it will display the correct ip address.

Thanks, Lockit.

Share this post


Link to post
Share on other sites

$ip=$_SERVER['REMOTE_ADDR']

if ($TEST)  { 
   $ip="another ip-address";
}

 

and make sue $TEST is set to 'true' when you test...

Share this post


Link to post
Share on other sites

Testing the final release is what i mean. The server will also use the script for routine things. However using sockets to export data to a program will not work if the ip is sent to the router.

Share this post


Link to post
Share on other sites

sorry, than i'm not sure about what you mean, because the solution i gave does not need any changes in code

 

esp. if you define the variable $TEST using an include statement..

 

include 'test.inc.php';

$ip=$_SERVER['REMOTE_ADDR']

if ($TEST)  {
    $ip="another ip-address";
}

 

and in this 'test.inc.php':

<?php
$TEST=True;
?>

 

after testing you only need to change the 'test.inc.php' file.....

Share this post


Link to post
Share on other sites

Hmm, I never was good with explanations.

I am not 100% sure something like this would work but what I am attempting falls along the lines of:

if($_SERVER['REMOTE_ADDR'] == "192.168.2.1") {
  $ip = (Some method to retrieve the real IP.);
} else {
  $ip = $_SERVER['REMOTE_ADDR'];
}

Share this post


Link to post
Share on other sites

hmm, i think if this is true

$_SERVER['REMOTE_ADDR'] == "192.168.2.1"

 

that '192.168.2.1' is the real ip-address (and AFAIK the only address that PHP is able to produce)

Share this post


Link to post
Share on other sites

seems this works every 5 attempts, however it uses the domain name instead of the numerical IP for the socket export.

 

if($_SERVER['REMOTE_ADDR'] == "192.168.2.1") {
  $address = $_SERVER['SERVER_NAME'];
} else {
  $address = $_SERVER['REMOTE_ADDR'];
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.