title: INET_ATON() and INET_NTOA() in PHP?
body: <p>I want to store IP addresses in my database, but I also need to use them throughout my application. I read about using <code>INET_ATON()</code> and <code>INET_NTOA()</code> in my MySQL queries to get a 32-bit unsigned integer out of an IP address, which is exactly what I want as it will make searching through the database faster than using char(15).</p>
  
  <p>The thing is, I can't find a function that does the same sort of thing in PHP. The only thing I came across is:</p>
  
  <p><a href="http://php.net/manual/en/function.ip2long.php" rel="noreferrer">http://php.net/manual/en/function.ip2long.php</a></p>
  
  <p>So I tested it:</p>
  
  <pre><code>$ip = $_SERVER['REMOTE_ADDR'];
  echo ip2long($ip);
  </code></pre>
  
  <p>And it outputs nothing. In the example they gave it seems to work, but then again I'm not exactly sure if <code>ip2long()</code> does the same thing as <code>INET_ATON()</code>.</p>
  
  <p>Does someone know a PHP function that will do this? Or even a completely new solution to storing an IP address in a database?</p>
  
  <p>Thanks.</p>