Location: PHPKode > scripts > getpostlib > getpostlib/doc/html/httplib_8php-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>getpostlib: httplib.php Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.3 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>httplib.php</h1><a href="httplib_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 
<a name="l00010"></a><a class="code" href="httplib_8php.html#a0">00010</a> function <a class="code" href="httplib_8php.html#a0">http_post</a>($server ,
<a name="l00011"></a>00011                 $port, 
<a name="l00012"></a>00012                 $url, 
<a name="l00013"></a>00013                 $cookie, 
<a name="l00014"></a>00014                 $vars 
<a name="l00016"></a>00016                 ) 
<a name="l00017"></a>00017 {
<a name="l00018"></a>00018         $user_agent = <span class="stringliteral">"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"</span>;
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00021"></a>00021         $urlencoded = <span class="stringliteral">""</span>;
<a name="l00022"></a>00022         <span class="keywordflow">while</span> (list($key,$value) = each($vars))
<a name="l00023"></a>00023                 $urlencoded.= urlencode($key) . <span class="stringliteral">"="</span> . urlencode($value) . <span class="stringliteral">"&amp;"</span>;
<a name="l00024"></a>00024         $urlencoded = substr($urlencoded,0,-1); 
<a name="l00025"></a>00025 
<a name="l00026"></a>00026         $content_length = strlen($urlencoded);
<a name="l00027"></a>00027 
<a name="l00028"></a>00028         $headers = <span class="stringliteral">"POST $url HTTP/1.1\r\nHost: $server\r\nAccept: */*\r\nAcceptLanguage: en-au\r\nConnection: close\r\nContent-Type: application/x-www-form-urlencoded\r\nUser-Agent: $user_agent\r\nCache-Control: no-cache\r\nCookie: {$cookie}\r\nContent-Length: $content_length\r\n\r\n"</span>;
<a name="l00029"></a>00029         
<a name="l00030"></a>00030         $fp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
<a name="l00031"></a>00031         
<a name="l00032"></a>00032         <span class="keywordflow">if</span> (!socket_connect($fp, $server, $port))
<a name="l00033"></a>00033         {
<a name="l00034"></a>00034                 socket_close($fp);
<a name="l00035"></a>00035                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00036"></a>00036         }
<a name="l00037"></a>00037 
<a name="l00038"></a>00038         socket_set_option($fp, SOL_SOCKET, SO_KEEPALIVE, TRUE);
<a name="l00039"></a>00039         socket_send($fp, $headers, strlen($headers), 0);
<a name="l00040"></a>00040         socket_send($fp, $urlencoded, strlen($urlencoded), 0);
<a name="l00041"></a>00041         
<a name="l00042"></a>00042         $ret = <span class="stringliteral">""</span>;
<a name="l00043"></a>00043         <span class="keywordflow">while</span> ($rd = socket_read($fp, 1024))
<a name="l00044"></a>00044         {
<a name="l00045"></a>00045                 $ret .= $rd;
<a name="l00046"></a>00046         }
<a name="l00047"></a>00047         
<a name="l00048"></a>00048         socket_close($fp);
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         $pos = strpos($ret, <span class="stringliteral">"\r\n\r\n"</span>);
<a name="l00051"></a>00051 
<a name="l00052"></a>00052         <span class="keywordflow">if</span> (!is_bool($pos))
<a name="l00053"></a>00053         {
<a name="l00054"></a>00054                 $ret = substr($ret, $pos);
<a name="l00055"></a>00055         }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057         <span class="keywordflow">return</span> $ret;
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 }
<a name="l00060"></a>00060 
<a name="l00067"></a><a class="code" href="httplib_8php.html#a1">00067</a> function <a class="code" href="httplib_8php.html#a1">http_get</a>($server,  
<a name="l00068"></a>00068                 $port, 
<a name="l00069"></a>00069                 $url, 
<a name="l00070"></a>00070                 $cookie,  
<a name="l00071"></a>00071                 $additional_fields = <span class="stringliteral">""</span> )
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074         $user_agent = <span class="stringliteral">"Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"</span>;
<a name="l00075"></a>00075 
<a name="l00076"></a>00076         $headers = <span class="stringliteral">"GET $url HTTP/1.1\r\nAccept: */*\r\nAccept-Language: en-au\r\nUser-Agent: $user_agent\r\nHost: $server\r\nCookie: {$cookie}\r\nCache-Control: no-cache\r\nConnection: close\r\n{$additional_fields}\r\n"</span>;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078         $fp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
<a name="l00079"></a>00079         <span class="keywordflow">if</span> (!socket_connect($fp, $server, $port))
<a name="l00080"></a>00080         {
<a name="l00081"></a>00081                 socket_close($fp);
<a name="l00082"></a>00082                 <span class="keywordflow">return</span> FALSE;
<a name="l00083"></a>00083         }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085         socket_set_option($fp, SOL_SOCKET, SO_KEEPALIVE, TRUE);
<a name="l00086"></a>00086         socket_send($fp, $headers, strlen($headers), 0);
<a name="l00087"></a>00087         
<a name="l00088"></a>00088         $ret = <span class="stringliteral">""</span>;
<a name="l00089"></a>00089         <span class="keywordflow">while</span> ($rd = socket_read($fp, 1024))
<a name="l00090"></a>00090         {
<a name="l00091"></a>00091                 $ret .= $rd;
<a name="l00092"></a>00092         }
<a name="l00093"></a>00093         
<a name="l00094"></a>00094         socket_close($fp);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096         $pos = strpos($ret, <span class="stringliteral">"\r\n\r\n"</span>);
<a name="l00097"></a>00097 
<a name="l00098"></a>00098         <span class="keywordflow">if</span> (!is_bool($pos))
<a name="l00099"></a>00099         {
<a name="l00100"></a>00100                 $ret = substr($ret, $pos);
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <span class="keywordflow">return</span> $ret;
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 ?&gt;
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed May 25 11:41:54 2005 for getpostlib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.3 </small></address>
</body>
</html>
Return current item: getpostlib