Current location: Hot Scripts Forums » Programming Languages » PHP » IP Address read / choice based


IP Address read / choice based

Reply
  #1 (permalink)  
Old 12-22-09, 04:03 PM
rog47776 rog47776 is offline
New Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
IP Address read / choice based

Hello all,

I am just looking for direction or a script (login) that will read the ip address / subnet from a browser-request, then match it against a list of previously entered addresses (of servers) to determine which server for the user to log into.

The login script already exisits and works. It uses a config.xml file with a list of servers with ip addresses. The user sees a drop down list of servers to choose from. I want to make their server (based off of the ip subnet---from their browser) show first in the list.

any help would be GREAT! thanks!
Reply With Quote
  #2 (permalink)  
Old 12-22-09, 08:01 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
What language / platform are you using?
Reply With Quote
  #3 (permalink)  
Old 12-22-09, 10:35 PM
rog47776 rog47776 is offline
New Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Oh geezz, I'm sorry. I am needing this for PHP. The login file is in PHP and the server list is in a config.xml file. I just need to know the code for reading the browser ip and for entering in ip subnets with the server list so that I can control the server first in the list.
Reply With Quote
  #4 (permalink)  
Old 12-23-09, 06:49 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Browser/Client IP address: $_SERVER['REMOTE_ADDR']

Not sure what you mean by 'entering in ip subnets'.

Possible resources for IP functions:

PHP: Bitwise Operators - Manual
PHP: Network Functions - Manual
Reply With Quote
  #5 (permalink)  
Old 12-23-09, 07:07 AM
rog47776 rog47776 is offline
New Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you for the reply. Here is some more detail:

The login.php is a simple login interface with user / pass and a drop-down list of servers (to login to). The server list is in a config.xml file that has a "friendly" server name matched to the actual server ip address.

What I want to do is put partial ip addresses or subnets to match certain servers. The partial address / subnet would be something like 10.12.64. Then, take the login.php and read the users browser / client ip address. If the users browser / client had the address of 10.12.64.125 (that would match the partial address/ subnet tied to a specific server). So, the net result would be the user would see the appropriate server first in the server drop-down list.

I have a snippet of code that does this in .NET / .ASP: I just need the same thing or basics for the same thing in PHP

if selectedsiteid="" or isNull(selectedsiteid) then
set rs_gets=widform.execute("select validate_woco,siteid,parentsiteid,subnet from site where subnet=substr('" & remote_addr & "',0,length(subnet))")
do while not rs_gets.eof
selectedsiteid=rs_gets.fields("siteid").value
parentsiteid=rs_gets.fields("parentsiteid").value
subnet=rs_gets.fields("subnet").value
validate_woco=rs_gets.fields("validate_woco").valu e
rs_gets.movenext
loop
'if Left(remote_addr,5)="10.12" then ' HO
' selectedsiteid="4"
' parentsiteid="4"
' end if
' if Left(remote_addr,5)="10.8." or Left(remote_addr,5)="10.9." then ' GR
' selectedsiteid="9"
' parentsiteid="9"
' end if
' if Left(remote_addr,5)="10.4." then ' AV
' selectedsiteid="0"
' parentsiteid="0"
Reply With Quote
  #6 (permalink)  
Old 12-27-09, 03:15 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Something like:
PHP Code:

<?php
//put your array here. Ordered the same as your select menu.
$IParray[] = '109.189.44.243';
$IParray[] = '109.192.185.38';
$IParray[] = '109.192.32.53';
$IParray[] = '109.74.193.250';
$IParray[] = '109.74.195.194';
$IParray[] = '109.86.25.129';
$IParray[] = '109.90.149.52';
$IParray[] = '113.255.115.223';
$IParray[] = '114.36.20.113';
$IParray[] = '115.163.53.185';
$IParray[] = '115.84.182.227';
$IParray[] = '116.52.139.115';
$IParray[] = '116.90.132.39';
$IParray[] = '117.18.75.235';
$IParray[] = '118.172.31.13';

//Getting the IP's from a file, un-comment the next line and delete the above array;
//$IParray = file('yourFile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

function getIPselected() {
    
$user $_SERVER['REMOTE_ADDR'];
    
    
$user_first_three substr($user,0,strrpos($user,'.'));
    
$user_first_two substr($user_first_three,0,strrpos($user_first_three,'.'));
    
$user_first substr($user_first_two,0,strrpos($user_first_two,'.'));
    
    global 
$IParray;
    
    foreach( 
$IParray as $key => $value ) {
    
        
$first_three substr($value,0,strrpos($value,'.'));
        
$first_two substr($first_three,0,strrpos($first_three,'.'));
        
$first substr($first_two,0,strrpos($first_two,'.'));
        
        if(
$user == $value) {
            
$match[$key] = 4;
        }
        elseif( 
$user_first_three == $first_three ) {
            
$match[$key] = 3;
        }
        elseif( 
$user_first_two == $first_two ) {
            
$match[$key] = 2;
        }
        elseif( 
$user_first == $first ) {
            
$match[$key] = 1;
        }
    }
    
    if(
count($match) == 0) { return 0; }
    else {
        for( 
$i 4$i 0$i--) {
            if(
in_array($i,$match)) {
                return 
array_search$i$match );
            }
        }
    }
}

$selector getIPselected();

echo 
'<select name="ip">';

foreach( 
$IParray as $key => $value) {

    echo 
'<option ';
    
        if(
$selector == $key) { echo 'selected="selected"'; }
        
    echo 
'>' $value '</option>';
    
}

echo 
'</select>';

?>
??

Last edited by Jcbones; 12-27-09 at 03:23 PM. Reason: Deleted de-bug code
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
rog47776 (12-28-09)
  #7 (permalink)  
Old 12-28-09, 09:53 AM
rog47776 rog47776 is offline
New Member
 
Join Date: Dec 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you very much! I can definitely use that to accomplish the auto server selection. I know my users will appreciate!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Response.Redirect based on IP address zarc ASP 10 09-26-11 12:42 PM
How to get the computer ip address through coding? nkamk Other Topics 6 04-12-11 12:29 AM
Freeze columns in a table Rita Negi Script Requests 1 09-01-09 08:23 AM
Ip Address Question? purpleman The Lounge 2 07-12-06 05:59 PM
page based proxy? curious, read on... id10tn00b ASP 0 10-07-04 11:11 AM


All times are GMT -5. The time now is 08:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.