开发者

How can I redirect the user after an amount of time using PHP and codeigniter? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a page that I want to load and display for an amount of time. The user should then be redirected back to the index view.

The code below is my controller.

function send()
{
    $data = array(
        'author' => $_POST['author'],
        'header' => $_POST['header'],
        'paragraph' => $_POST['paragraph']
    );

    $result = $this->database_model->insert_into_articles($data);

    if( $result )
    {

        $view['content'] = "articles_send_view";
            $this->load->view('includes/template',$view );

    }

}

The following is my view.

<div id="content">
<div id='other_content'>
<p>
    artic开发者_开发百科le sent thanks 
</p>

</div>


I don't believe this can be done with PHP alone. You have two options in HTML.

A <meta http-equiv="refresh"> tag in your <head> can be used to reload or redirect the user after a specified number of seconds. Wikipedia has a couple of examples:

Place inside <head> to refresh page after 5 seconds:

<meta http-equiv="refresh" content="5">

Redirect to http://example.com/ after 5 seconds:

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

Redirect to http://example.com/ immediately:

<meta http-equiv="refresh" content="0; url=http://example.com/">

The other option is to use JavaScript to redirect the user. You can do this by modifying the window.location property, using the setTimeout function to delay the call for, for example, five seconds (5000 miliseconds).

var redirect = function() {
    window.location = "/index.html";
};

setTimeout(redirect, 5000);

The <meta> redirect should work for almost all visitors, while the JavaScript won't work if they have JavaScript disabled. However, these don't conflict in any way so you could just include both on your page to be safe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜