I have been using fsockopen() to access remote web pages for processing without any problems (until now).

Example data:

URL: http://www.dvdstreet.infront.co.uk/cgi-bin/show?key=dvd-CDR30990

If you go to the URL shown above, you will get redirected to another page. How is this done? Why can't I find any reference to a redirect in the headers I get back?

Here's the story:

I open a socket on port 80 (HTTP) using fsockopen and then use the data shown above to derive an HTTP REQUEST:

e.g.
open HOST: www.dvdstreet.infront.co.uk
use PATH: cgi-bin/show?key=dvd-CDR30990

REQUEST:
GET /cgi-bin/show?key=dvd-CDR30990 HTTP/1.0

My script reports:

Completed page read (17 lines found)

And the HTTP headers returned are:

HTTP/1.1 302 Found
Date: Fri, 22 Jun 2001 19:04:45 GMT
Server: Apache/1.3.19 (Unix) ApacheJServ/1.1
Location: http://www.infront.co.uk/?key=dvd-CDR30990
Connection: close
Content-Type: text/html; charset=iso-8859-1

And the page returned says:

Found

The document has moved here.

When I click on the link behind the word "here", it doesn't go to the same page that I would see in my browser.

What is going on? Have I lost the plot here somewhere?

All help gratefully received.

Richard

    The key is the HTTP response code, which in your case is 302. This means the server is telling your browser the actual page is somewhere else, and the browser automagically redirects to the new page. Here's the offical HTTP 1.1 RFC definition:

    10.3.3 302 Found

    The requested resource resides temporarily under a different URI.
    Since the redirection might be altered on occasion, the client SHOULD
    continue to use the Request-URI for future requests. This response
    is only cacheable if indicated by a Cache-Control or Expires header
    field.

    The temporary URI SHOULD be given by the Location field in the
    response. Unless the request method was HEAD, the entity of the
    response SHOULD contain a short hypertext note with a hyperlink to
    the new URI(s).
    If the 302 status code is received in response to a request other
    than GET or HEAD, the user agent MUST NOT automatically redirect the
    request unless it can be confirmed by the user, since this might
    change the conditions under which the request was issued.

      Note: RFC 1945 and RFC 2068 specify that the client is not allowed
      to change the method on the redirected request.  However, most
      existing user agent implementations treat 302 as if it were a 303
      response, performing a GET on the Location field-value regardless
      of the original request method. The status codes 303 and 307 have
      been added for servers that wish to make unambiguously clear which
      kind of reaction is expected of the client.

      Thanks for the pointers but my problem is:

      The link returned by the request sent via fsockopen() does not take me to the same page that I get if I enter the URL in my browser window.

      How is this done? What can I do to identify the correct URL when using fsockopen() ?

      To use your phrase - how does the browser "automagically" know where to redirect me to?

        7 months later

        Your browser creates a new socket when it's redirected I asume

          Write a Reply...