Redirect with php

Discussion in 'PHP' started by ingilizdili, Jan 17, 2011.

  1. #1
    Hello;
    My question is not as simple as the title suggests.
    I am sure you all know what the following code does:
    <meta http-equiv="refresh" content="800;url=http://www.paniad.org/index.php" />
    HTML:
    Is it possible to do it using php?
    In other words, it it possible with php to force the visitor out of the page after a certain period, 800 seconds, for example?
     
    ingilizdili, Jan 17, 2011 IP
  2. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    PHP is server script, server cannot wait 800s to redirect
    You can use this script:
    
    echo '<meta http-equiv="refresh" content="800;url=http://www.paniad.org/index.php" />';
    
    PHP:
     
    langtusitinh225, Jan 17, 2011 IP
  3. Riboflavin

    Riboflavin Well-Known Member

    Messages:
    1,091
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    155
    #3
    I think this is what you want:

    <?php
    sleep(800);
    header("Location: http://www.example.com/");
    ?>
    PHP:
     
    Riboflavin, Jan 17, 2011 IP
  4. swashata

    swashata Member

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Browser will definitely give a Network Timeout error if you sleep for 800s. So, langtusitinh225 is correct that server cannot wait for 800s to redirect.

    As of your problem, it seems, the user sees the page, now if forgets to close the page, then after 800sec he is redirected to a new page. This can be solved with meta tag or JS only. Best is combination of both ;)
     
    swashata, Jan 18, 2011 IP
  5. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    You can do this by using meta tag or js
    In js you can use setTimeout function
     
    langtusitinh225, Jan 18, 2011 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?php header('refresh:800;url=http://www.paniad.org/index.php');  ?>
    PHP:
     
    danx10, Jan 18, 2011 IP
  7. phprunner

    phprunner Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can also use Javascript for this purpose:

    <script type="text/javascript">
    window.setTimeout('window.location = "http://www.paniad.org/index.php"',800*1000);
    </script>
    
    HTML:
     
    phprunner, Jan 19, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #8
    wow, best solution here!

    +rep!
     
    G3n3s!s, Jan 22, 2011 IP