SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    echo, sleep, header -- how!

    I have a problem here.. I'm not sure how to solve it:

    When i log out a user, I do
    header ("Location: www.site.com");

    But This results in them clicking logout, and being brought directly to www.site.com, it does not display "You are now logged out".

    I want to display "you are logged out" for 5 seconds, and THEN send them to site.com

    I know to use the sleep function to wait 5 seconds, but I cant send the user any message like "you are now logged out" because then the

    header ("Location: www.site.com");

    wil not work, because output has already started)

    So --
    how do i have the script do an echo statement, wait 5 seconds, AND THEN redirect the user?
    Marc Gugliuzza
    marc.gugliuzza.com



  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may need to use a client side technology like javascript to achieve this.

    PHP Code:
    <?
        
    if($logout == 1) {
            
    ?>
            You are no Logged Out!.... Redirecting
            <script language="JavaScript1.2">
            <!--
            function goHome() { location.href = 'http://localhost/'; }
            setTimeout("goHome();", 1000);
            //-->
            </script>
            <?
            
    }
        else {
    ?>


    <a href="<?=$PHP_SELF?>?logout=1">logout</a>

    <?
            
    }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could always redirect them to a holding page e.g. loggedout.htm and then in the page display the logged out message and use a meta refresh to take them to the home page after 5 seconds.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  4. #4
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, good ideas both, thanks!

    Looks like im going to have to use some client side scripting to accomplish this I thought it might be so.
    Last edited by Marc; Oct 19, 2001 at 12:16.
    Marc Gugliuzza
    marc.gugliuzza.com



  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I still don't see why you need the new page.

    PHP Code:
    <html>
    <head>

    </head>
    <body>

    <?
        
    if($logout == 1) {
            
    ?>
            You are no Logged Out!.... Redirecting
            <meta http-equiv="refresh" content="5;url=http://localhost">
            <?
            
    exit;
            }
        else {
    ?>


    <a href="<?=$PHP_SELF?>?logout=1">logout</a>

    <?
            
    }
    ?>

    </body>
    </html>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    This is all Mumbo Jumbo Amit's Avatar
    Join Date
    Oct 2001
    Location
    New Delhi, India
    Posts
    277
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you can try this ....

    Code:
    Header("Refresh: 5;url=http://www.yoururl.com");
    echo "Logging Out ..... ";

  7. #7
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah genius

    Header("Refresh: 5;url=http://www.yoururl.com");

    delays exactly 5 seconds, i assume

    thanks a bunch everyone.

    btw, freddy, your code does work perfectly, thanks !
    Marc Gugliuzza
    marc.gugliuzza.com




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •