Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. why invalid IP is valid?

why invalid IP is valid?

Scheduled Pinned Locked Moved Web Development
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I am using PHP and I am trying to validate IP address to check if valid IPv4, IPv6 or invalid. but when I am connected to localhost I am getting IP address as ::1 it says:

    ::1 is a valid IPv6 address

    How can I fix it please?

    $ip = $_SERVER['REMOTE_ADDR'];

    if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false)
    {
    echo("

    " . "$ip is a valid IPv6 address");
    }
    else if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false)
    {
    echo("

    " . "$ip is not valid IPv4 address");
    }
    else
    {
    echo("

    " . "invalid address");
    }

    Thanks, Jassim[^]

    Technology News @ www.JassimRahma.com

    L 1 Reply Last reply
    0
    • J Jassim Rahma

      Hi, I am using PHP and I am trying to validate IP address to check if valid IPv4, IPv6 or invalid. but when I am connected to localhost I am getting IP address as ::1 it says:

      ::1 is a valid IPv6 address

      How can I fix it please?

      $ip = $_SERVER['REMOTE_ADDR'];

      if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false)
      {
      echo("

      " . "$ip is a valid IPv6 address");
      }
      else if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false)
      {
      echo("

      " . "$ip is not valid IPv4 address");
      }
      else
      {
      echo("

      " . "invalid address");
      }

      Thanks, Jassim[^]

      Technology News @ www.JassimRahma.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yet another question that could be answered with a quick Google search: ::1 ipv6 - Google Search[^].

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups