PHP Classes

File: test_http_cookies.php

Recommend this page to a friend!
  Classes of Manuel Lemos   PHP HTTP protocol client   test_http_cookies.php   Download  
File: test_http_cookies.php
Role: Example script
Content type: text/plain
Description: Script to test cookie support
Class: PHP HTTP protocol client
HTTP client to access Web site pages
Author: By
Last change: Avoided passing arguments explicitly by reference.
Used the GetRequestArguments function to setup the connection and request
arguments.
Corrected the example URL.
Avoided PHP short tags.
Date: 13 years ago
Size: 2,103 bytes
 

Contents

Class file image Download
<?php
/*
 * test_http_cookies.php
 *
 * @(#) $Header: /opt2/ena/metal/http/test_http_cookies.php,v 1.3 2003/10/28 22:09:35 mlemos Exp $
 *
 */

   
$user=""; /* Define your PHP Classes site access name here */ $user_line=__LINE__;
   
$password=""; /* Define your PHP Classes site access name here */ $password_line=__LINE__;
   
$url="http://www.phpclasses.org/login.html?page=/browse.html/file/5/download/1/name/http.php";
    if(
$user=="")
    {
        echo
"PHP Classes site user was not specified in script ".__FILE__." line $user_line\n";
        exit;
    }

    if(
$password=="")
    {
        echo
"PHP Classes site password was not specified in script ".__FILE__." line $password_line\n";
        exit;
    }

    require(
"http.php");

   
set_time_limit(0);
   
$http=new http_class;
   
$http->GetRequestArguments($url,$arguments);
   
$error=$http->Open($arguments);
    if(
$error=="")
    {
       
$arguments["RequestMethod"]="POST";
       
$arguments["PostValues"]=array(
           
"alias"=>$user,
           
"password"=>$password,
           
"Submit"=>"Login",
           
"dologin"=>"1"
       
);
       
$error=$http->SendRequest($arguments);
        if(
$error=="")
        {
           
$error=$http->ReadReplyHeaders($headers);
            if(
$error=="")
            {
                for(
$header=0,Reset($headers);$header<count($headers);Next($headers),$header++)
                {
                    if(
Key($headers)=="set-cookie")
                        break;
                }
                if(
$header<count($headers))
                {
                    for(;;)
                    {
                       
$error=$http->ReadReplyBody($body,1000);
                        if(
$error!=""
                       
|| strlen($body)==0)
                            break;
                    }
                }
                else
                   
$error="This page did not set a cookie";
            }
            if(
$error==""
           
&& ($error=$http->Close())==""
           
&& ($error=$http->Open(array(
               
"HostName"=>$arguments["HostName"]
            )))==
""
           
&& ($error=$http->SendRequest(array(
                   
"RequestURI"=>$arguments["RequestURI"],
                   
"RequestMethod"=>"GET"
           
)))==""
           
&& ($error=$http->ReadReplyHeaders($headers))=="")
            {
                for(;;)
                {
                   
$error=$http->ReadReplyBody($body,1000);
                    if(
$error!=""
                   
|| strlen($body)==0)
                        break;
                    echo
$body;
                }
            }
        }
       
$close_error=$http->Close();
        if(
$error=="")
           
$error=$close_error;
    }
    if(
$error!="")
        echo
"Error: $error\n";
?>