SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict CeleronXL's Avatar
    Join Date
    Dec 2002
    Location
    United States of America
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page Redirection

    How do you redirect people from pages to page in PHP? I don't mean by using the header() function.

    I want to know how to have a page load, show whatever content is on it for like 2 seconds, and then redirect to the next page. Header() doesn't do this, it pulls immediately to the next page, and it must be called before anything is output. Thus, you can't output anything.. So how do you redirect after a short time?

  2. #2
    Lost
    Join Date
    Dec 2002
    Location
    Norway
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was working on something similar a while back, but everyone told me to use javascript instead as doing this was so much easier with java then with php.

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    lisboa
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you let us know your solution?

  4. #4
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easy enough, and you don't even have to use PHP or anything else. HTML can do this with the use of a meta tag.

    Code:
    <meta http-equiv="refresh" content="2[<-how long you want it to wait before loading the next page]; url=[your-url-here]" />
    Cheers.

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function redirectJS($url) {
            ?>
            <script language='javascript1.2' type='text/javascript'>
                window.location = '<?php echo($url); ?>';
            </script>
            <?php
        
    }


    redirectJS('index.php'); // to use it
    Enjoy.

  6. #6
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by darker
    I was working on something similar a while back, but everyone told me to use javascript instead as doing this was so much easier with java then with php.
    You can't redirect a page with PHP after it is sent to the browser. PHP is a server-side language, it is being processed on the server and the output is then send to the browser.

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you set a time delay so there is time to read a short message?

    Thanks,

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use the meta redirect code from above, that is how it's been done for the past 10 years and you can set the time just like the code says.

    It's a meta tag so it goes in the <HEAD> of the page you want to display for just a few seconds. Here's an example with a 5 second delay:

    <meta http-equiv="refresh" content="5; url=http://www.websitegoodies.com" />

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Palm Desert, California
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply..

    I know about putting the metta tag in the head of a HTML document but How would I use it with PHP..

    The PHP code above works great but I just need to slow it down a couple seconds..

    Thanks

  10. #10
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is no PHP code above

    If the page you want to show before the redirect is a static HTML file, put it in the head. If the page you want to show before the redirect is generated by your PHP program, make the PHP program put the META tag in that page. In an echo if you're using those.

    If you need more help, you need someone to do it for you, so post the PHP script here that generates the page you want to show for a few seconds and I'll help you modify it, or someone else here will.


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
  •