Basic Authentication

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

    Basic Authentication

    I need to send a request from my server
    running PHP to another server which is using
    Basic Authentication.

    How is this done?

    I know the realm, username, and password.

    Thanks,

    Andrew


  • Janwillem Borleffs

    #2
    Re: Basic Authentication

    Andrew wrote:[color=blue]
    > I need to send a request from my server
    > running PHP to another server which is using
    > Basic Authentication.
    >
    > How is this done?
    >
    > I know the realm, username, and password.
    >[/color]

    Basic realm authentication:

    $fp = fsockopen("host .com", 80);
    fputs($fp, "GET / HTTP/1.0\r\n");
    fputs($fp, "Host: host.com\r\n");
    fputs($fp, "Authorizat ion: basic
    ".base64_encode ("login:passwor d")."\r\n\r\n") ;

    fpassthru($fp);


    JW



    Comment

    • Janwillem Borleffs

      #3
      Re: Basic Authentication

      Janwillem Borleffs wrote:[color=blue]
      > fputs($fp, "Authorizat ion: basic
      > ".base64_encode ("login:passwor d")."\r\n\r\n") ;
      >[/color]

      Watch for newsreader line breaks, this header should be on one line:

      fputs($fp,
      "Authorizat ion: basic " .
      base64_encode(" login:password" ) .
      "\r\n\r\n"
      );


      JW



      Comment

      • Andrew

        #4
        Re: Basic Authentication

        [color=blue]
        > Basic realm authentication:
        >
        > $fp = fsockopen("host .com", 80);
        > fputs($fp, "GET / HTTP/1.0\r\n");
        > fputs($fp, "Host: host.com\r\n");
        > fputs($fp, "Authorizat ion: basic
        > ".base64_encode ("login:passwor d")."\r\n\r\n") ;
        >
        > fpassthru($fp);[/color]

        Thanks for the info.

        I have a couple more questions:

        1. Is required to send the realm?

        2. I want to use ImageCreateFrom JPEG(URL)
        to grab the image from the password protected
        server. Can I use the authentication code above
        to "unlock" the server then just call this function?

        Regards,

        Andrew





        Comment

        • Janwillem Borleffs

          #5
          Re: Basic Authentication

          Andrew wrote:[color=blue]
          > 1. Is required to send the realm?
          >[/color]

          Only its type, in this case 'basic'.
          [color=blue]
          > 2. I want to use ImageCreateFrom JPEG(URL)
          > to grab the image from the password protected
          > server. Can I use the authentication code above
          > to "unlock" the server then just call this function?
          >[/color]

          No, you will first have to retrieve the image data and store it in a
          variable or a temporary file before you call the imagecreatefrom jpeg()
          function.


          JW



          Comment

          • Chung Leong

            #6
            Re: Basic Authentication

            "Andrew" <andrew@nowhere nohow.com> wrote in message
            news:lCvKc.7162 $Qu5.5856@newsr ead2.news.pas.e arthlink.net...[color=blue]
            > I need to send a request from my server
            > running PHP to another server which is using
            > Basic Authentication.
            >
            > How is this done?
            >
            > I know the realm, username, and password.
            >
            > Thanks,
            >
            > Andrew
            >[/color]

            The cleanest way is to use stream_context_ create() to create a HTTP context
            for POST, then pass the context to fopen(). This method requires a fairly
            up-to-date version of PHP, however.


            Comment

            Working...