<HTML ><HEAD ><TITLE >socket_getpeername</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Socket functions" HREF="ref.sockets.html"><LINK REL="PREVIOUS" TITLE="socket_get_option" HREF="function.socket-get-option.html"><LINK REL="NEXT" TITLE="socket_getsockname" HREF="function.socket-getsockname.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.socket-get-option.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.socket-getsockname.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.socket-getpeername" ></A >socket_getpeername</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN87412" ></A ><P > (PHP 4 >= 4.1.0)</P >socket_getpeername -- Queries the remote side of the given socket which may either result in host/port or in a UNIX filesystem path, dependent on its type. </DIV ><DIV CLASS="refsect1" ><A NAME="AEN87415" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >socket_getpeername</B > ( resource socket, string &addr [, int &port])<BR ></BR ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >This function is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >EXPERIMENTAL</I ></SPAN >. The behaviour of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk.</P ></TD ></TR ></TABLE ></DIV ><P > If the given socket is of type <TT CLASS="constant" ><B >AF_INET</B ></TT >, <B CLASS="function" >socket_getpeername()</B > will return the peers (remote) <SPAN CLASS="emphasis" ><I CLASS="emphasis" >IP address</I ></SPAN > in dotted-quad notation (e.g. <TT CLASS="literal" >127.0.0.1</TT >) in the <TT CLASS="parameter" ><I >address</I ></TT > parameter and, if the optional <TT CLASS="parameter" ><I >port</I ></TT > parameter is present, also the associated port. </P ><P > If the given socket is of type <TT CLASS="constant" ><B >AF_UNIX</B ></TT >, <B CLASS="function" >socket_getpeername()</B > will return the UNIX filesystem path (e.g. <TT CLASS="literal" >/var/run/daemon.sock</TT >) in the <TT CLASS="parameter" ><I >address</I ></TT > parameter. </P ><P > Returns <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. <B CLASS="function" >socket_getpeername()</B > may also return <TT CLASS="constant" ><B >FALSE</B ></TT > if the socket type is not any of <TT CLASS="constant" ><B >AF_INET</B ></TT > or <TT CLASS="constant" ><B >AF_UNIX</B ></TT >, in which case the last socket error code is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >not</I ></SPAN > updated. </P ><P > See also <B CLASS="function" >socket_getpeername()</B >, <A HREF="function.socket-last-error.html" ><B CLASS="function" >socket_last_error()</B ></A > and <A HREF="function.socket-strerror.html" ><B CLASS="function" >socket_strerror()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.socket-get-option.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.socket-getsockname.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >socket_get_option</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sockets.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >socket_getsockname</TD ></TR ></TABLE ></DIV ></BODY ></HTML >