Basic Authentication question.

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

    Basic Authentication question.

    Hi group.
    I've got Basic Authentication working almost fine, so I need to resolve a
    little problem.
    I've got this code in my php scrip:

    <?php
    $fp = fsockopen("www. mydomain.com",8 0);
    fputs($fp,"GET /downloads HTTP/1.0\r\n");
    fputs($fp,"Host : www.mydomain.co m\r\n");
    fputs($fp,"Auth orization: Basic " . base64_encode(" user:pass") . "\r\n\
    \n");
    fpassthru($fp);
    ?>

    This works almost fine.
    I say almost because I can't stop showing the server response string from my
    page:
    "HTTP/1.1 200 OK Date: Fri, 23 Jul 2004 17:37:40 GMT Server: Apache/1.3.31
    (Unix) PHP/4.3.6 Connection: close Content-Type: text/html"

    How can I stop showing this text from in my page?

    Best regards,

    Nuno Paquete.
  • Daniel Tryba

    #2
    Re: Basic Authentication question.

    Nuno Paquete <nmp@ispgaya.pt > wrote:[color=blue]
    > $fp = fsockopen("www. mydomain.com",8 0);
    > fputs($fp,"GET /downloads HTTP/1.0\r\n");
    > fputs($fp,"Host : www.mydomain.co m\r\n");
    > fputs($fp,?utho rization: Basic " . base64_encode(? ser:pass") . "\r\n\
    > \n");
    > fpassthru($fp);
    > ?>
    >
    > This works almost fine.
    > I say almost because I can't stop showing the server response string from my
    > page:
    > "HTTP/1.1 200 OK Date: Fri, 23 Jul 2004 17:37:40 GMT Server: Apache/1.3.31
    > (Unix) PHP/4.3.6 Connection: close Content-Type: text/html"
    >
    > How can I stop showing this text from in my page?[/color]

    Don't use fpassthru... use fgets. Headers are the lines till the first
    "empty" line, munch them and output the rest.

    while(!feof($fp ) && strlen(rtrim(fg ets($fp)))!==0) ;

    while(!feof($fp ))
    {
    echo fgets($fp);
    }

    (untested)

    --

    Daniel Tryba

    Comment

    • Nuno Paquete

      #3
      Re: Basic Authentication question.

      Daniel Tryba wrote:
      [color=blue]
      > Nuno Paquete <nmp@ispgaya.pt > wrote:[color=green]
      >> $fp = fsockopen("www. mydomain.com",8 0);
      >> fputs($fp,"GET /downloads HTTP/1.0\r\n");
      >> fputs($fp,"Host : www.mydomain.co m\r\n");
      >> fputs($fp,?utho rization: Basic " . base64_encode(? ser:pass") . "\r\n\
      >> \n");
      >> fpassthru($fp);
      >> ?>
      >>
      >> This works almost fine.
      >> I say almost because I can't stop showing the server response string from
      >> my page:
      >> "HTTP/1.1 200 OK Date: Fri, 23 Jul 2004 17:37:40 GMT Server:
      >> Apache/1.3.31 (Unix) PHP/4.3.6 Connection: close Content-Type: text/html"
      >>
      >> How can I stop showing this text from in my page?[/color]
      >
      > Don't use fpassthru... use fgets. Headers are the lines till the first
      > "empty" line, munch them and output the rest.
      >
      > while(!feof($fp ) && strlen(rtrim(fg ets($fp)))!==0) ;
      >
      > while(!feof($fp ))
      > {
      > echo fgets($fp);
      > }
      >
      > (untested)
      >[/color]


      Thanks. That's it.

      Comment

      Working...