Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ip addresses and redirect

Status
Not open for further replies.

meiteens

Programmer
Jan 18, 2001
14
LV
hello!

i don't know much of php, so i think i would need hours to figure out how to do it, but for you probably it would take only a minute, so maybe someone could help..

so.. i need a script which checks the users ip address and when the ip address starts for example with 123.456.789.xxx (the xxx would be any value), then the user is redirected to another page..

thanks,
gunta
 
Here is how I have done it:

if (strncmp ("123.456.789.xxx", $REMOTE_ADDR, 12) == 0)
header ("Location: else
header ("Location:

The strncmp() function
takes three variables:
string 1 and string 2 are the two strings you want to compair. The third variable is the number of characters you want to include in the comparison. In my example, I used the first 12 characters of the IP address (you must include the periods between the address notations as characters). If the address you wanted to accept was 12.34.XXX.XXX, then the len (third variable) would be 6.

I am not sure if this is the best way, but it seems to work fairly well and the code is pretty short.
 
They should add an "Edit Post" function in this system.

The posting system keeps adding semi-colons in my code ... remove the first ; in both of the lines that start with header.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top