angelcause Posted December 26, 2014 Share Posted December 26, 2014 I am writing a script which will be dependent on the client's public ip address. e.g. if the client is using ip address 203.122.55.124 script A should run and if else then script B should run. Now I know that the If and else will be used but cant guess how will the public ip be captured. Please help Quote Link to comment Share on other sites More sharing options...
kicken Posted December 26, 2014 Share Posted December 26, 2014 $_SERVER['REMOTE_ADDR'] contains the address of the client. Using the IP to make decisions is generally a poor idea though. What are you trying to accomplish exactly? What does script A and script B do? 1 Quote Link to comment Share on other sites More sharing options...
superromia Posted December 30, 2014 Share Posted December 30, 2014 Consider getting country from the public ip to make decisions. Try this, IP2Location db1 lite. Its free to use and provide you the country of the user based on the IP address. A variety of APIs is also provided. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted December 30, 2014 Share Posted December 30, 2014 (edited) Consider getting country from the public ip to make decisions. Try this, IP2Location db1 lite. Its free to use and provide you the country of the user based on the IP address. A variety of APIs is also provided. That's if the OP want's to do geolocation Edited December 30, 2014 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
CroNiX Posted December 30, 2014 Share Posted December 30, 2014 Hope it's not a dynamic IP (which changes). Otherwise you'll have to be updating your code constantly. I think a log in system would be much better with permissions/user levels. If 'administrator' logs in, run script A, if 'maintainer' logs in, run script B, etc. Quote Link to comment Share on other sites More sharing options...
angelcause Posted January 1, 2015 Author Share Posted January 1, 2015 Actually I have a script which runs in two modes - Local Host and WAN. The IP I am using is like 203.135.37.204 Here is what I want I have 2 scripts Script A and Script B Now I want the script to see if the public address of client is the above (203.135.37.204) then it should run script A else it should run script B Quote Link to comment Share on other sites More sharing options...
Solution QuickOldCar Posted January 1, 2015 Solution Share Posted January 1, 2015 if($_SERVER['REMOTE_ADDR'] == "203.135.37.204"){ include("scripta.php"); } else { include("scriptb.php"); } 1 Quote Link to comment Share on other sites More sharing options...
Barand Posted January 1, 2015 Share Posted January 1, 2015 I'd test for localhost otherwise remote. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.