PHP Classes

PHP HTTP protocol client: HTTP client to access Web site pages

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum (147)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-07-11 (8 months ago) RSS 2.0 feedStarStarStarStar 69%Total: 47,260 This week: 7All time: 6 This week: 12Down
Version License PHP version Categories
httpclient 1.0.9BSD License3Networking, HTTP, Web services
Description 

Author

Class that implements requests to Web resources using the HTTP protocol.

It features:

- May submit HTTP requests with any method, to any page, to any server, connecting to any port.
- Provides support to setup connection and request arguments from a given URL.
- May submit requests via a proxy server with support for authentication if necessary.
- May establish connections via a SOCKS server.
- Supports HTTP direct access or proxy based authentication mechanisms via SASL class library like HTTP Basic, HTTP Digest or NTLM (Windows or Samba).
- Support secure connections (https) via Curl library with SSL support, or at least PHP 4.3.0 with OpenSSL support, or via a non-SSL HTTP proxy server.
- Supports accessing secure pages using SSL certificates and private keys using Curl library
- Supports user defined request headers.
- Supports POST requests with a user defined array of form values.
- Supports POST requests with a user defined request bodies for instance for making requests to SOAP services.
- Supports streaming requests that require uploading large amounts of data of undefined length in small chunks to avoid exceeding PHP memory limits
- Supports requests to sites hosting virtual Web servers.
- Retrieves the HTTP response headers and body data separately.
- Support HTTP 1.1 chunked content encoding
- Supports session and persistent cookies.
- Provides optional handling of redirected pages.
- Supports defining connection and data transfer timeout values.
- Can output connection debug information in plain text or formatted as HTML.
- An add-on class is provided to login to Yahoo sites and perform actions on the behalf of the logged users like exporting the user address book or sending invitation to a group.

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos is available for providing paid consulting. Contact Manuel Lemos .
Classes: 45 packages by
Country: Portugal Portugal
Age: 55
All time rank: 1
Week rank: 2 Down1 in Portugal Portugal Equal

Recommendations

Recommendation for a PHP class to access faucet pay
Access Faucet Pay API

Microsoft Text to Speech PHP API program
Microsoft text to speech PHP API program

Link Checker
Find broken links in a Web site

Multiple search engine search retrieval and storage
Need a engine to query different search engines

Upload file to directory of my server with download link
How I can upload this file to my server with download link

Access file and get response from hosted domain to localhost
Send variable values from localhost to a PHP script in a domain

What is the best PHP http client class?
HTTP client for PHP version 5.3

Example

<?php
/*
 * test_http.php
 *
 * @(#) $Header: /opt2/ena/metal/http/test_http.php,v 1.19 2011/01/27 02:18:18 mlemos Exp $
 *
 */

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Test for Manuel Lemos' PHP HTTP class</TITLE>
</HEAD>
<BODY>
<H1 align="center">Test for Manuel Lemos' PHP HTTP class</H1>
<HR>
<UL>
<?php
   
require("http.php");

   
/* Uncomment the line below when accessing Web servers or proxies that
     * require authentication.
     */
    /*
    require("sasl.php");
    */

   
set_time_limit(0);
   
$http=new http_class;

   
/* Connection timeout */
   
$http->timeout=0;

   
/* Data transfer timeout */
   
$http->data_timeout=0;

   
/* Output debugging information about the progress of the connection */
   
$http->debug=1;

   
/* Format dubug output to display with HTML pages */
   
$http->html_debug=1;


   
/*
     * Need to emulate a certain browser user agent?
     * Set the user agent this way:
     */
   
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

   
/*
     * If you want to the class to follow the URL of redirect responses
     * set this variable to 1.
     */
   
$http->follow_redirect=1;

   
/*
     * How many consecutive redirected requests the class should follow.
     */
   
$http->redirection_limit=5;

   
/*
     * If your DNS always resolves non-existing domains to a default IP
     * address to force the redirection to a given page, specify the
     * default IP address in this variable to make the class handle it
     * as when domain resolution fails.
     */
   
$http->exclude_address="";

   
/*
     * If you want to establish SSL connections and you do not want the
     * class to use the CURL library, set this variable to 0 .
     */
   
$http->prefer_curl=0;

   
/*
     * If basic authentication is required, specify the user name and
     * password in these variables.
     */

   
$user="";
   
$password="";
   
$realm=""; /* Authentication realm or domain */
   
$workstation=""; /* Workstation for NTLM authentication */
   
$authentication=(strlen($user) ? UrlEncode($user).":".UrlEncode($password)."@" : "");

/*
    Do you want to access a page via SSL?
    Just specify the https:// URL.
    $url="https://www.openssl.org/";
*/

   
$url="http://".$authentication."www.php.net/";

   
/*
     * Generate a list of arguments for opening a connection and make an
     * HTTP request from a given URL.
     */
   
$error=$http->GetRequestArguments($url,$arguments);

    if(
strlen($realm))
       
$arguments["AuthRealm"]=$realm;

    if(
strlen($workstation))
       
$arguments["AuthWorkstation"]=$workstation;

   
$http->authentication_mechanism=""; // force a given authentication mechanism;

    /*
     * If you need to access a site using a proxy server, use these
     * arguments to set the proxy host and authentication credentials if
     * necessary.
     */
    /*
    $arguments["ProxyHostName"]="127.0.0.1";
    $arguments["ProxyHostPort"]=3128;
    $arguments["ProxyUser"]="proxyuser";
    $arguments["ProxyPassword"]="proxypassword";
    $arguments["ProxyRealm"]="proxyrealm"; // Proxy authentication realm or domain
    $arguments["ProxyWorkstation"]="proxyrealm"; // Workstation for NTLM proxy authentication
    $http->proxy_authentication_mechanism=""; // force a given proxy authentication mechanism;
    */

    /*
     * If you need to access a site using a SOCKS server, use these
     * arguments to set the SOCKS host and port.
     */
    /*
    $arguments["SOCKSHostName"]='127.0.0.1';
    $arguments["SOCKSHostPort"]=1080;
    $arguments["SOCKSVersion"]='5';
    */

    /* Set additional request headers */
   
$arguments["Headers"]["Pragma"]="nocache";
/*
    Is it necessary to specify a certificate to access a page via SSL?
    Specify the certificate file this way.
    $arguments["SSLCertificateFile"]="my_certificate_file.pem";
    $arguments["SSLCertificatePassword"]="some certificate password";
*/

/*
    Is it necessary to preset some cookies?
    Just use the SetCookie function to set each cookie this way:

    $cookie_name="LAST_LANG";
    $cookie_value="de";
    $cookie_expires="2010-01-01 00:00:00"; // "" for session cookies
    $cookie_uri_path="/";
    $cookie_domain=".php.net";
    $cookie_secure=0; // 1 for SSL only cookies
    $http->SetCookie($cookie_name, $cookie_value, $cookie_expiry, $cookie_uri_path, $cookie_domain, $cookie_secure);
*/


   
echo "<LI><H2>Opening connection to:</H2>\n<P><TT>",HtmlSpecialChars($arguments["HostName"]),"</TT></P>\n";
   
flush();
   
$error=$http->Open($arguments);
    echo
"</LI>\n";

    if(
$error=="")
    {
        echo
"<LI><H2>Sending request for page:</H2>\n<P><TT>";
        echo
HtmlSpecialChars($arguments["RequestURI"]),"\n";
        if(
strlen($user))
            echo
"\nLogin: ",$user,"\nPassword: ",str_repeat("*",strlen($password));
        echo
"</TT></P>\n";
       
flush();
       
$error=$http->SendRequest($arguments);
        echo
"</LI>\n";

        if(
$error=="")
        {
            echo
"<LI><H2>Request:</H2>\n<PRE>\n".HtmlSpecialChars($http->request)."</PRE></LI>\n";
            echo
"<LI><H2>Request headers:</H2>\n<PRE>\n";
            for(
Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
            {
               
$header_name=Key($http->request_headers);
                if(
GetType($http->request_headers[$header_name])=="array")
                {
                    for(
$header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
                        echo
$header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n";
                }
                else
                    echo
$header_name.": ".$http->request_headers[$header_name],"\r\n";
            }
            echo
"</PRE>\n";
           
flush();

           
$headers=array();
           
$error=$http->ReadReplyHeaders($headers);
            echo
"</LI>\n";
            if(
$error=="")
            {
                echo
"<LI><H2>Response status code:</H2>\n<P>".$http->response_status;
                switch(
$http->response_status)
                {
                    case
"301":
                    case
"302":
                    case
"303":
                    case
"307":
                        echo
" (redirect to <TT>".$headers["location"]."</TT>)<BR>\nSet the <TT>follow_redirect</TT> variable to handle redirect responses automatically.";
                        break;
                }
                echo
"</P></LI>\n";
                echo
"<LI><H2>Response headers:</H2>\n<PRE>\n";
                for(
Reset($headers),$header=0;$header<count($headers);Next($headers),$header++)
                {
                   
$header_name=Key($headers);
                    if(
GetType($headers[$header_name])=="array")
                    {
                        for(
$header_value=0;$header_value<count($headers[$header_name]);$header_value++)
                            echo
$header_name.": ".$headers[$header_name][$header_value],"\r\n";
                    }
                    else
                        echo
$header_name.": ".$headers[$header_name],"\r\n";
                }
                echo
"</PRE></LI>\n";
               
flush();

                echo
"<LI><H2>Response body:</H2>\n<PRE>\n";

               
/*
                    You can read the whole reply body at once or
                    block by block to not exceed PHP memory limits.
                */

                /*
                $error = $http->ReadWholeReplyBody($body);
                if(strlen($error) == 0)
                    echo HtmlSpecialChars($body);
                */

               
for(;;)
                {
                   
$error=$http->ReadReplyBody($body,1000);
                    if(
$error!=""
                   
|| strlen($body)==0)
                        break;
                    echo
HtmlSpecialChars($body);
                }

                echo
"</PRE></LI>\n";
               
flush();
            }
        }
       
$http->Close();
    }
    if(
strlen($error))
        echo
"<H2 align=\"center\">Error: ",$error,"</H2>\n";
?>
</UL>
<HR>
</BODY>
</HTML>


Screenshots  
  • httpclient.gif
  Files folder image Files  
File Role Description
Accessible without login Plain text file classmaps.php Aux. Class maps definition
Plain text file http.php Class HTTP class file
Accessible without login Plain text file LICENSE.txt Lic. BSD like license
Accessible without login Plain text file test_cookies.php Test Unit test script to verify cookie manipulation functions
Accessible without login Plain text file test_http.php Example HTTP class test page script
Accessible without login Plain text file test_http_cookies.php Example Script to test cookie support
Accessible without login Plain text file test_http_image_request.php Example Example script on how to request an image from a remote site to made available through a local server
Accessible without login Plain text file test_http_post.php Example Emulate a form submission using HTTP POST submitting form field values including file uploads
Accessible without login Plain text file test_http_soap.php Example Example script on how to make a request to SOAP service
Accessible without login Plain text file yahoo_export_address_book.php Example Script to login in Yahoo and export the user address book
Accessible without login Plain text file yahoo_group_invite.php Example Script to login in Yahoo and invite users to a Yahoo!Groups mailing list
Plain text file yahoo_user.php Class Class to login and access resources for Yahoo registered users

Downloadhttpclient-2023-07-11.zip 33KB
Downloadhttpclient-2023-07-11.tar.gz 29KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Simple Authentication and Security Layer Download .zip .tar.gz When the HTTP server requires authentication, the SASL package provides support for implementing authentication mechanisms like: Basic, Digest, PLAIN, LOGIN, CRAM-MD5, NTLM (Windows or Linux/Unix with Samba). Conditional
 Version Control Reuses Unique User Downloads Download Rankings  
 92%18
Total:47,260
This week:7
All time:6
This week:12Down
User Ratings User Comments (17)
 All time
Utility:89%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:-
Examples:82%StarStarStarStarStar
Tests:79%StarStarStarStar
Videos:-
Overall:69%StarStarStarStar
Rank:321
 
Excellent package.
9 years ago (Diol)
80%StarStarStarStarStar
like it
10 years ago (Samir Das)
80%StarStarStarStarStar
I've been using this class on a client side PHP-GTK2/Gnope GU...
11 years ago (NotInterested)
75%StarStarStarStar
Good ides and job!
12 years ago (Victor Storm)
75%StarStarStarStar
Great class, widely used.
12 years ago (MWL Online)
80%StarStarStarStarStar
Good
14 years ago (kishore kumar)
80%StarStarStarStarStar
stable script, robust but missing explanation of all options/...
14 years ago (Rosetree)
75%StarStarStarStar
Hi, I started using your class instead of Snoopy in my librar...
16 years ago (Kepler Gelotte)
80%StarStarStarStarStar
I really loved you HTTP and yahoo_user classes.
15 years ago (banbuu_nattchan)
72%StarStarStarStar
Wonderful pack!
15 years ago (Alex B. Snet)
80%StarStarStarStarStar
Excellent work, sir - this has saved a huge amount of effort.
15 years ago (Ken)
80%StarStarStarStarStar
This class saved my quite a bit of low-level socket programmi...
15 years ago (Klaus Kuplen)
70%StarStarStarStar
Huge great thanks!
15 years ago (dasdasd)
80%StarStarStarStarStar
Dear php professional that calss is really good but how can w...
15 years ago (Abdulkadir KUCUK)
72%StarStarStarStar
Very useful class
16 years ago (Murilo Klock Ferreira)
80%StarStarStarStarStar
Good Class
16 years ago (Mark Watson)
75%StarStarStarStar
The Lemos HttpClient class is the BEST-OF-THE-BEST (no doubt).
16 years ago (LeoLeo)
75%StarStarStarStar