PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 26th, 2000, 01:30 PM
bigotes bigotes is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 1999
Location: Santo Domingo, DN, Dominican Republic
Posts: 1 bigotes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've been trying to determine if a string coming from an html form is a valid IP address, I tried using the regexp's functions, but I can't hit the clown yet, so I'm asking you out if you can give me a hand on here.

I've split the string on 4 strings more separated by ".", then determine if each of those is a number, but... what if the user enters just letters??

Some help would be appreceiated... URL

------------------
Bigotes :{

Reply With Quote
  #2  
Old May 26th, 2000, 03:45 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
A regex solution might be an idea but I'd hate to tackle it since the range is not easy to deal with. I see this as four steps:

1) break up the elements
2) verify number of elements=4
3) verify all integers
4) verify valid range

to wit:
$invalid=0;
$levels=explode('.',$ip);
if (count($levels)!=4) $invalid='true';
for ($i=0;$i<4;$i++)
{
if ($levels[$i]!=intval($levels[$i]) $invalid='true';
if ($levels[$i]<0 OR $levels[$i]>256) $invalid='true';
}

if ($invalid)
{
// $ip not a valid ip address
}else
{
// $ip valid
}

Technically some values of $ip would not be valid that would slip thru, but this should be good enough for most applications.

HTH

Rod

Reply With Quote
  #3  
Old May 27th, 2000, 04:01 AM
Natrak Natrak is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Oslo, Norway
Posts: 5 Natrak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I use:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
if (ereg("[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}",$ip)) {
print "The IP is valid.";
}
else {
print("The IP is not valid.");
}
[/code]

If you want to check everything you could make sure its not part of the 10.* A class or the 192.168.* B class since those are reserved for private networks.

N.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Valid IP in php

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap