Get http response codes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bart op de grote markt

    Get http response codes

    Hello

    I have a website in php in which I have some kind of portal to external
    links that come from a database. When a user clicks on a link,
    "link.php" is called, does some stuff (e.g. adds 1 to the visit-count
    of that certain page) and then forwards the user with a location-header
    to the asked page. Now my question: is it possible to get the
    response-code of that asked page? E.g. when code 404 is returned, I
    can put that in the database and then it's easy for me to know when a
    link is broken.

    Kind regards,

    Bart

  • Sjoerd

    #2
    Re: Get http response codes


    Bart schreef op de grote markt:
    I have a website in php in which I have some kind of portal to external
    links that come from a database. When a user clicks on a link,
    "link.php" is called, does some stuff (e.g. adds 1 to the visit-count
    of that certain page) and then forwards the user with a location-header
    to the asked page. Now my question: is it possible to get the
    response-code of that asked page? E.g. when code 404 is returned, I
    can put that in the database and then it's easy for me to know when a
    link is broken.
    No. When you send a location header to the client, the client requests
    the page it is redirected to. Your PHP page only points to the new
    page, but is not involved in the retrieval of it. Therefore, it can not
    retrieve the headers or the page itself, and thus not the return code
    which is part of the headers.

    Comment

    • Michael Fesser

      #3
      Re: Get http response codes

      ..oO(Bart op de grote markt)
      >I have a website in php in which I have some kind of portal to external
      >links that come from a database. When a user clicks on a link,
      >"link.php" is called, does some stuff (e.g. adds 1 to the visit-count
      >of that certain page) and then forwards the user with a location-header
      >to the asked page. Now my question: is it possible to get the
      >response-code of that asked page? E.g. when code 404 is returned, I
      >can put that in the database and then it's easy for me to know when a
      >link is broken.
      No, because it's the browser that request the other page, not your
      script.

      But you could let your script perform such a check from time to time:
      Maybe every 10th click on that link (or if the last check was more than
      1 month ago) your script itself could send a request to the other site
      to check its state. If the check succeeds, store the result in your DB
      and send the redirect to the browser.

      Micha

      Comment

      • Bart op de grote markt

        #4
        Re: Get http response codes


        Michael Fesser schreef:

        But you could let your script perform such a check from time to time:
        Maybe every 10th click on that link (or if the last check was more than
        1 month ago) your script itself could send a request to the other site
        to check its state. If the check succeeds, store the result in your DB
        and send the redirect to the browser.
        >
        Micha
        Ok, thx, I'm already a lot wiser and maybe this is what I'm going to
        do. It's a nice suggestion.

        Bart

        Comment

        • rh

          #5
          Re: Get http response codes


          "Bart op de grote markt" <bartwarnez@fre egates.bewrote in message
          news:1162215727 .250479.229640@ i42g2000cwa.goo glegroups.com.. .
          Hello
          >
          I have a website in php in which I have some kind of portal to external
          links that come from a database. When a user clicks on a link,
          "link.php" is called, does some stuff (e.g. adds 1 to the visit-count
          of that certain page) and then forwards the user with a location-header
          to the asked page. Now my question: is it possible to get the
          response-code of that asked page? E.g. when code 404 is returned, I
          can put that in the database and then it's easy for me to know when a
          link is broken.
          >
          Kind regards,
          >
          Bart
          >
          Yes.

          When link.php "does some stuff" have it send a HEAD request to the link
          url.

          If it comes back as "200 Ok" forward the user to the page, if it comes back
          as "404 Not Found" or any other error response show the user an error page
          on your site and log the error for that link.

          If the response comes back with a 3** redirect, you could parse that url
          and check it (possibly set up a loop to check multiple redirects), forward
          the user, or just show an error if you don't want the links to redirect
          your users.


          Rich


          Comment

          Working...