Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    Hello,
    I need to write some php to show different code depending on the ip address of the computer. If the ip is in the 10.30 range, I need to show a link going to one page. for all others, I need to show a link to go to another page. Any ideas???
    Thanks,
    Mikael

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Yeah, look up the [minicode]$_SERVER['REMOTE_ADDR'][/minicode] variable. Remember that IPs can be spoofed, however.

  4. #3
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    how would i fit this into an if statement and an ip address range?

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    At it's simplest, something like this:
    PHP Code:
    if (preg_match("^10\\.30\\.\\d{1,3}\\.\\d{1,3}$"$_SERVER['REMOTE_ADDR']) == 1)
        
    // it's in the range
    else
        
    // it isn't in the range 
    Alternatively:
    PHP Code:
    if (strpos($_SERVER['REMOTE_ADDR'], '10.30.') === 0)
        
    // it's in the range, since the position of that string is at the very beginning
    else
        
    // it isn't in the range 

  6. #5
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    Thanks So Much!!!
    (haven't done php in a while)

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    No problem


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:13 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com