Web Design Forum: Class C of IP in PHP? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Class C of IP in PHP? Rate Topic: -----

#1 User is offline   wkdfx 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 89
  • Joined: 09-June 08
  • Reputation: 0
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 13 March 2010 - 11:32 AM

Hi,

Would anyone know a way of getting the Class C of a domain/IP address in PHP?

the gethostbyname() functions will return the IP but is there another function to get the Class C address?

I would appreciate your help on this!!

Thanks

WkdFX
0

#2 User is offline   davewilly 

  • Dedicated Member
  • PipPip
  • View gallery
  • Group: Members
  • Posts: 155
  • Joined: 09-November 08
  • Reputation: 5
  • Gender:Male
  • Location:Bristol / Cheddar
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 13 March 2010 - 11:36 AM

View Postwkdfx, on 13 March 2010 - 11:32 AM, said:

Hi,

Would anyone know a way of getting the Class C of a domain/IP address in PHP?

the gethostbyname() functions will return the IP but is there another function to get the Class C address?

I would appreciate your help on this!!

Thanks

WkdFX


Class C is just the 3rd subset of the IP (I think) - 192.168.2

Can't you just chop the end off $_SERVER["REMOTE_ADDR"] ?

Unless I'm mistaken with regards to what Class C IP actually is, this will do it.

<?php

preg_match('/^(?P<class_c>[^\.]+.[^\.]+.[^\.]+)/', $_SERVER["REMOTE_ADDR"], $match);
    
echo $match['class_c'];
  
?>


Dave
0

#3 User is offline   wkdfx 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 89
  • Joined: 09-June 08
  • Reputation: 0
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 13 March 2010 - 03:45 PM

Nice one Dave!

This is perfect
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users