reading Response Headers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ross

    reading Response Headers

    Hi Group,
    I am working on web service where I am trying to execute a
    remote URL from within a php file and would like to make some
    decisions depending on the output.

    I am using fopen to open the URL
    $handle=@fopen( "www.mysite .com/api/command","r");

    If the command is successful it returns an XML file with
    response headers. I have no problems reading the XML.

    I am interested in the response header which has a session-ID.
    how do I access this information.
    any inputs are greatly appreciated..
    Thanks a bunch,
    Regards,
    Ross

  • Stefan Rybacki

    #2
    Re: reading Response Headers

    ross wrote:[color=blue]
    > Hi Group,
    >...
    >[/color]

    I guess a socket connection will help you.



    Regards
    Stefan

    Comment

    • Iván Sánchez Ortega

      #3
      Re: reading Response Headers

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      ross wrote:
      [color=blue]
      > I am interested in the response header which has a session-ID.
      > how do I access this information.[/color]

      By using CURL functions to execute the HTTP query and grab the entire
      results.

      - --
      - ----------------------------------
      Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

      http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
      MSN:i_eat_s_p_a _m_for_breakfas t@hotmail.com
      Jabber:ivansanc hez@jabber.org ; ivansanchez@kde talk.net
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.2 (GNU/Linux)

      iD8DBQFDiGKl3jc Q2mg3Pc8RAmUMAJ 9LRLDlwL2UQJFWD gLUsTmU+B2vDQCe NiPi
      7VRsczkuWWKJAQv EpyXL98s=
      =g4+Q
      -----END PGP SIGNATURE-----

      Comment

      • VS

        #4
        Re: reading Response Headers

        Stefan Rybacki wrote:[color=blue]
        > ross wrote:
        >[color=green]
        >> Hi Group,
        >> ...
        >>[/color]
        >
        >
        > I guess a socket connection will help you.
        >
        > http://de3.php.net/fsockopen[/color]

        Here's an exmaple I found and use to get the last modified time of a
        remote file:

        function filemtime_remot e($uri)
        {
        $uri = parse_url($uri) ;
        $uri['port'] = isset($uri['port']) ? $uri['port'] : 80;

        // TimeOut
        $tout = 5;
        $handle = @fsockopen($uri['host'], $uri['port'], $errno, $errstr,
        $tout);
        if(!$handle)
        return 0;

        fputs($handle," HEAD $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
        $result = 0;
        while(!feof($ha ndle))
        {
        $line = fgets($handle,1 024);
        if(!trim($line) )
        break;

        $col = strpos($line,': ');
        if($col !== false)
        {
        $header = trim(substr($li ne,0,$col));
        $value = trim(substr($li ne,$col+1));
        if(strtolower($ header) == 'last-modified')
        {
        $result = strtotime($valu e);
        break;
        }
        }
        }
        fclose($handle) ;
        return $result;
        }

        $URL="http://www.xxxxx.com/filename.txt";
        $tsrem = filemtime_remot e($URL);

        --
        VS

        Comment

        Working...