Lockit Posted March 4, 2010 Share Posted March 4, 2010 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. Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/ Share on other sites More sharing options...
jskywalker Posted March 4, 2010 Share Posted March 4, 2010 $ip=$_SERVER['REMOTE_ADDR'] if ($TEST) { $ip="another ip-address"; } and make sue $TEST is set to 'true' when you test... Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021300 Share on other sites More sharing options...
Lockit Posted March 4, 2010 Author Share Posted March 4, 2010 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. Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021315 Share on other sites More sharing options...
jskywalker Posted March 4, 2010 Share Posted March 4, 2010 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..... Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021336 Share on other sites More sharing options...
Lockit Posted March 4, 2010 Author Share Posted March 4, 2010 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']; } Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021362 Share on other sites More sharing options...
jskywalker Posted March 4, 2010 Share Posted March 4, 2010 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) Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021366 Share on other sites More sharing options...
Lockit Posted March 4, 2010 Author Share Posted March 4, 2010 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']; } Link to comment https://forums.phpfreaks.com/topic/194108-remote-addr-local-testing/#findComment-1021384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.