How do i creat a php url after 3 seconds?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Breana
    New Member
    • Aug 2007
    • 117

    How do i creat a php url after 3 seconds?

    I need to create a a simple load index.php after 3 seconds with php.

    On my login page i want it to say Welcome back, $userid
    Loding page... and have it load the index.php after 3 seconds is this possible?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You mean something like this:
    [code=php]
    header('Refresh : 3; url=index.php') ;
    print 'Welcome back, $userid. You will be redirected in 3 seconds!';
    [/code]

    Comment

    • Breana
      New Member
      • Aug 2007
      • 117

      #3
      [code=php]<? header('Refresh : 3; url=index.php') ; ?>[/code]
      Dont seem to work, i cant use it in my header.php or it will load all pages after 3 seconds...

      Or did i do the above code wrong?

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        This, as with all headers, must be done before anything is printed (or echoed) (or otherwise sent) to the output.

        If that doesn't work for you you could always cheat and use JavaScript...
        [code=php]
        echo "Redirectin g in 3 seconds...";
        echo '
        <script type="text/javascript">
        setTimeout(func tion(){location .href="index.ph p";}, 3000);
        </script>';
        [/code]

        Comment

        • Breana
          New Member
          • Aug 2007
          • 117

          #5
          Ok, i dident know it had to be at the very top lol.
          It works thanx :)

          SOLVED!

          Comment

          • JeremyMiller
            New Member
            • Sep 2007
            • 69

            #6
            Originally posted by Atli
            Hi.

            You mean something like this:
            [code=php]
            header('Refresh : 3; url=index.php') ;
            print 'Welcome back, $userid. You will be redirected in 3 seconds!';
            [/code]

            I think you meant

            [code=php]
            header('Refresh : 3; url=index.php') ;
            print "Welcome back, $userid. You will be redirected in 3 seconds!";
            [/code]

            That will replace $userid with the value instead of showing $userid itself.

            Comment

            • kovik
              Recognized Expert Top Contributor
              • Jun 2007
              • 1044

              #7
              Also, just an FYI, the "Refresh" header is not supported by all browsers. I believe <meta> redirection is a more reliable choice.

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                Originally posted by volectricity
                Also, just an FYI, the "Refresh" header is not supported by all browsers. I believe <meta> redirection is a more reliable choice.
                True. But I've tested the "Refresh" header in all my usual browsers (IE, FF, Opera, Safari) and they all support it.

                Honestly, if your browser doesn't support basic things like this, you should seriously consider switching browsers!
                (Tho I strongly suspect that you, like me, have at least a couple of browser set up :)

                Originally posted by JeremyMiller
                I think you meant

                [code=php]
                header('Refresh : 3; url=index.php') ;
                print "Welcome back, $userid. You will be redirected in 3 seconds!";
                [/code]

                That will replace $userid with the value instead of showing $userid itself.
                She said she wanted to print $userid :P
                But your right. My example would indeed not print the value of $userid.

                Comment

                Working...