PHP refresh window? equivalent to F5 page reload?

前端 未结 10 2521
后悔当初
后悔当初 2021-01-01 23:45

Is there anything in PHP that is the equivalent of manually pressing the F5 page reload button? My php script is in a frame and isn\'t the parent script but it needs to ref

相关标签:
10条回答
  • 2021-01-02 00:05

    PHP cannot force the client to do anything. It cannot refresh the page, let alone refresh the parent of a frame.

    EDIT: You can of course, make PHP write JavaScript, but this is not PHP doing, it's actually JavaScript, and it will fail if JavaScript is disabled.

    <?php
        echo '<script>parent.window.location.reload(true);</script>';
    ?>
    
    0 讨论(0)
  • 2021-01-02 00:05

    with php you can use two redirections. It works same as refresh in some issues.

    you can use a page redirect.php and post your last url to it by GET method (for example). then in redirect.php you can change header to location you`ve sent to it by GET method.

    like this: your page:

    <?php
    header("location:redirec.php?ref=".$your_url);
    ?>
    

    redirect.php:

    <?php
    $ref_url=$_GET["ref"];
    header("location:redirec.php?ref=".$ref_url);
    ?>
    

    that worked for me good.

    0 讨论(0)
  • 2021-01-02 00:12

    guess you could echo the meta tag to do the refresh in regular intervals ... like

    <meta http-equiv="refresh" content="600" url="your-url-here"> 
    
    0 讨论(0)
  • 2021-01-02 00:12

    All you need to do to manually refresh a page is to provide a link pointing to the same page

    Like this: Refresh the selection

    0 讨论(0)
  • 2021-01-02 00:12

    Adding following in the page header works for me:

    <?php
    
    if($i_wanna_reload_the_full_page_on_top == "yes")
    {
    $reloadneeded = "1";
    }
    else
    {
    $reloadneeded = "0";
    }
    
    if($reloadneeded > 0)
    {
    ?>
    <script type="text/javascript">
    top.window.location='indexframes.php';
    </script>
    <?php
    }else{}
    ?>
    
    0 讨论(0)
  • 2021-01-02 00:19

    If you have any text before a

    header('Location: http://www.example.com/youformhere.php');
    

    you'll have issues, because that must be sent before any other text is sent to the page.

    Try using this code instead

    <?php 
    $page = $_SERVER['PHP_SELF'];
    echo '<meta http-equiv="Refresh" content="0;' . $page . '">';
    ?>
    

    Just remember, this code will create and infinite loop, so you'll probably need to make some conditional changes to it.

    0 讨论(0)
提交回复
热议问题