Redirect before header...?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    Redirect before header...?

    Greetings!

    I have a php page where I need to redirect the request but for this i need a script loaded first..

    Something like:
    Code:
    <script language="JavaScript">
      function StatusChange(text) {window.status = text; window.status = ''} 
    </script>
    and later...
    Code:
    header("Location: JavaScript: StatusChange ('screen')");
    How is this possible when PHP demands the redirect code BEFORE any header?
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    I hope you are missing something here. May be first you need to understand the difference between the server side scripting language and client side scripting language.

    Comment

    • Pheddy
      New Member
      • Dec 2008
      • 80

      #3
      Originally posted by ak1dnar
      I hope you are missing something here. May be first you need to understand the difference between the server side scripting language and client side scripting language.
      Ok lets say I need a page to be loaded fully with header and everything, and this page is counting down for a redirect. like on most download sites.. Maybe this where a better way to ask? Please say if im still not understanding.
      And forget the JS code..

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Pheddy, What you get on your browser when accessing the url of the web is a rendered HTML output of the php script. So there is no way to call the php header() function from your JS code.

        If you need to redirect your page after a certain time, again that is impossible only with PHP. So your best approach for that would be a javascript based redirection with a timer.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Originally posted by ak1dnar
          So your best approach for that would be a javascript based redirection with a timer.
          there’s also the HTML refresh meta tag.

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Originally posted by Dormilich
            there’s also the HTML refresh meta tag.
            Yep, I agree but I guess we need a script based solution for this as he/she has mentioned that
            ....this page is counting down for a redirect....
            So there should be a visible time countdown on the page.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by ak1dnar
              Yep, I agree but I guess we need a script based solution for this as he/she has mentioned that
              when I look at the given code, it is not that obvious to me. the given Javascript function is useless, the PHP code (actually it’s the HTTP code) is wrong. all that remains is a redirect, which can be 100% done in HTML, no Javascript required. although Javascript will make it looking pretty… (you can still do that as addition)

              and while I’m at it, a javascript download timer can easily be bypassed… ah, and to start a download, you do not use a redirect (well, at least not most of the time).

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                As Dorm said, PHP is not needed.
                If you want a timer and do not want to be limited by something as simple as turning your javascript off: use meta refresh and have a javascript timer totally separate (counting down on its own). Also display a message that if their javascript is off, they will not see the timer, but they have 30secs or what ever.

                Basically meta refresh will refresh regardless, provided their browser has not been tweaked, but I think that would defeat the point anyway if it forwards to a download.

                I think, Dorm, that this is a system that will have a premium option which will not require waiting, which is why a redirect is desired to start a download.

                Comment

                Working...