PHP redirect timeout

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

    PHP redirect timeout

    Hi All,

    Can anyone suggest a reliable solution to php redirect?:

    header("Locatio n: $redir_url");
    if the above times out in $timeout seconds
    header("Locatio n: $alt_redir_url" );

    Many thanks,

    Dave


  • Jerry Stuckle

    #2
    Re: PHP redirect timeout

    Dave wrote:[color=blue]
    > Hi All,
    >
    > Can anyone suggest a reliable solution to php redirect?:
    >
    > header("Locatio n: $redir_url");
    > if the above times out in $timeout seconds
    > header("Locatio n: $alt_redir_url" );
    >
    > Many thanks,
    >
    > Dave
    >
    >[/color]

    Hi, Dave,

    Sorry, you can't do it.

    When you send the redirect, the request goes to the browser. The browser is now
    responsible for fetching the new page. Your script is no longer "in the loop".

    Maybe you could do it with javascript - I haven't tried. But that would have
    its own problems (i.e. user has disabled javascript).

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Karl Groves

      #3
      Re: PHP redirect timeout

      Jerry Stuckle <jstucklex@attg lobal.net> wrote in
      news:ZsGdnYorq-4TNrTZ4p2dnA@co mcast.com:
      [color=blue]
      > Dave wrote:[color=green]
      >> Hi All,
      >>
      >> Can anyone suggest a reliable solution to php redirect?:
      >>
      >> header("Locatio n: $redir_url");
      >> if the above times out in $timeout seconds
      >> header("Locatio n: $alt_redir_url" );
      >>
      >> Many thanks,
      >>
      >> Dave
      >>
      >>[/color]
      >
      > Hi, Dave,
      >
      > Sorry, you can't do it.
      >
      > When you send the redirect, the request goes to the browser. The
      > browser is now responsible for fetching the new page. Your script is
      > no longer "in the loop".
      >
      > Maybe you could do it with javascript - I haven't tried. But that
      > would have its own problems (i.e. user has disabled javascript).
      >[/color]

      Actually, what could be done is to check for a good response at new URL
      with fsockopen() and if successful, do the redirect, otherwise go to the
      alternate.

      To the OP:
      peruse the info here: http://us2.php.net/function.fsockopen



      --
      Karl Groves



      Accessibility Discussion List: http://smallerurl.com/?id=6p764du

      Comment

      • Dave

        #4
        Re: PHP redirect timeout

        Actually, what I ended up doing was to use curl to request a very small
        graphic from the site.
        Used curl timeout to control the redirect time and got just the header.

        $timeout = 10;
        $testurl = "www.example.co m/small.gif";

        $ch = curl_init();
        curl_setopt($ch , CURLOPT_HEADER, 1);
        curl_setopt($ch , CURLOPT_NOBODY, 1);
        curl_setopt($ch , CURLOPT_URL,$te sturl);
        curl_setopt($ch , CURLOPT_RETURNT RANSFER,1);
        curl_setopt($ch , CURLOPT_TIMEOUT , $timeout);
        $source = curl_exec($ch);
        curl_close($ch) ;

        if ($source!="") // optionally I could have tested for HTTP status, 404,
        301, etc.
        $url = "http://www.example.com/";
        else
        $url = "http://www.example.net/";
        header("Locatio n: $url");

        Thanks to all who responded,

        Dave


        "Karl Groves" <karl@NOSPAMkar lcore.com> wrote in message
        news:Xns9794A94 E12584karlkarlc orecom@216.196. 97.136...[color=blue]
        > Jerry Stuckle <jstucklex@attg lobal.net> wrote in
        > news:ZsGdnYorq-4TNrTZ4p2dnA@co mcast.com:
        >[color=green]
        >> Dave wrote:[color=darkred]
        >>> Hi All,
        >>>
        >>> Can anyone suggest a reliable solution to php redirect?:
        >>>
        >>> header("Locatio n: $redir_url");
        >>> if the above times out in $timeout seconds
        >>> header("Locatio n: $alt_redir_url" );
        >>>
        >>> Many thanks,
        >>>
        >>> Dave
        >>>
        >>>[/color]
        >>
        >> Hi, Dave,
        >>
        >> Sorry, you can't do it.
        >>
        >> When you send the redirect, the request goes to the browser. The
        >> browser is now responsible for fetching the new page. Your script is
        >> no longer "in the loop".
        >>
        >> Maybe you could do it with javascript - I haven't tried. But that
        >> would have its own problems (i.e. user has disabled javascript).
        >>[/color]
        >
        > Actually, what could be done is to check for a good response at new URL
        > with fsockopen() and if successful, do the redirect, otherwise go to the
        > alternate.
        >
        > To the OP:
        > peruse the info here: http://us2.php.net/function.fsockopen
        >
        >
        >
        > --
        > Karl Groves
        > http://karlcore.com
        > http://chevelle.karlcore.com
        >
        > Accessibility Discussion List: http://smallerurl.com/?id=6p764du[/color]


        Comment

        • Jerry Stuckle

          #5
          Re: PHP redirect timeout

          Dave wrote:[color=blue]
          > Actually, what I ended up doing was to use curl to request a very small
          > graphic from the site.
          > Used curl timeout to control the redirect time and got just the header.
          >
          > $timeout = 10;
          > $testurl = "www.example.co m/small.gif";
          >
          > $ch = curl_init();
          > curl_setopt($ch , CURLOPT_HEADER, 1);
          > curl_setopt($ch , CURLOPT_NOBODY, 1);
          > curl_setopt($ch , CURLOPT_URL,$te sturl);
          > curl_setopt($ch , CURLOPT_RETURNT RANSFER,1);
          > curl_setopt($ch , CURLOPT_TIMEOUT , $timeout);
          > $source = curl_exec($ch);
          > curl_close($ch) ;
          >
          > if ($source!="") // optionally I could have tested for HTTP status, 404,
          > 301, etc.
          > $url = "http://www.example.com/";
          > else
          > $url = "http://www.example.net/";
          > header("Locatio n: $url");
          >
          > Thanks to all who responded,
          >
          > Dave
          >
          >
          > "Karl Groves" <karl@NOSPAMkar lcore.com> wrote in message
          > news:Xns9794A94 E12584karlkarlc orecom@216.196. 97.136...
          >[color=green]
          >>Jerry Stuckle <jstucklex@attg lobal.net> wrote in
          >>news:ZsGdnYor q-4TNrTZ4p2dnA@co mcast.com:
          >>
          >>[color=darkred]
          >>>Dave wrote:
          >>>
          >>>>Hi All,
          >>>>
          >>>>Can anyone suggest a reliable solution to php redirect?:
          >>>>
          >>>>header("Loc ation: $redir_url");
          >>>>if the above times out in $timeout seconds
          >>>>header("Loc ation: $alt_redir_url" );
          >>>>
          >>>>Many thanks,
          >>>>
          >>>>Dave
          >>>>
          >>>>
          >>>
          >>>Hi, Dave,
          >>>
          >>>Sorry, you can't do it.
          >>>
          >>>When you send the redirect, the request goes to the browser. The
          >>>browser is now responsible for fetching the new page. Your script is
          >>>no longer "in the loop".
          >>>
          >>>Maybe you could do it with javascript - I haven't tried. But that
          >>>would have its own problems (i.e. user has disabled javascript).
          >>>[/color]
          >>
          >>Actually, what could be done is to check for a good response at new URL
          >>with fsockopen() and if successful, do the redirect, otherwise go to the
          >>alternate.
          >>
          >>To the OP:
          >>peruse the info here: http://us2.php.net/function.fsockopen
          >>
          >>
          >>
          >>--
          >>Karl Groves
          >>http://karlcore.com
          >>http://chevelle.karlcore.com
          >>
          >>Accessibili ty Discussion List: http://smallerurl.com/?id=6p764du[/color]
          >
          >
          >[/color]

          All this does is mean you can access it from your site at that time.

          It doesn't mean, for instance, the user can access it - there may be a
          communications problem somewhere between the user and the target site, for instance.

          And of course there's the slight chance the site will go down between the time
          you request the graphic and the time the redirect takes effect. But the odds of
          that happening are pretty remote unless you're doing hundreds of redirects per
          minute.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Chung Leong

            #6
            Re: PHP redirect timeout

            Jerry Stuckle wrote:[color=blue]
            >
            > Maybe you could do it with javascript - I haven't tried. But that would have
            > its own problems (i.e. user has disabled javascript).
            >[/color]

            It can't really be done reliably in Javascript either, with cross-site
            scripting restrictions keeping you from detecting the state of the
            target site. All I think can of is to link to a image on the target
            site, then check to see if its dimensions are corrected. That obviously
            wouldn't work if the image happens to be sitting in the browser cache.

            Comment

            Working...