开发者

PHP redirection/popup: Keep existing page and pop up a new tab

开发者 https://www.devze.com 2023-01-01 23:56 出处:网络
I read that we can use the following in the meta tags for red开发者_运维百科irection to another page after desired number of minutes:

I read that we can use the following in the meta tags for red开发者_运维百科irection to another page after desired number of minutes:

<meta http-equiv="Refresh" content="10; url=http://www.example.com/" />

That is fine if it's acceptable to navigate away from the page that user is on. But what I am trying to do is that instead of navigating to another page, I want to pop up a new browser tab/window and also have the existing page as it is. I would like to do this strictly without Javascript.

So consider an example. Say user arrives on 1.php page. Now user will have 10 minutes to read the information on this page. At the end of 10 minutes, I want to pop up a new tab/window which points to the page 2.php and shows the information contained in it. So after the 10 minute, I will have 1.php page as it is and a new tab/window that shows 2.php page. I don't want to disturb the user for whatever he is doing on 1.php and hence want to just pop-up 2.php page.

How can I achieve this without using javascript/ajax?

Thank you in advance.

EDIT1:

If there is no way to do achieve this in PHP, how can I achieve this via Javascript? I would want to launch a popup/popunder to 2.php to be able to achieve this functionality and keep the user on the same page as he was on.

Thanks.


Just increase your session max timeout in php.ini, or do periodic (and unnoticeable by the user) AJAX requests to the server to keep the session alive.

Users simply do not want obtrusive popups, especially if the user has no idea what the purpose of the popup is for.


If all you want is extending the user session (based on you comments), a javascript-less way might be to create a hidden <iframe> that refers to a page that auto-refreshes and keeps the session alive.

Ex, in your main page you'll have:

<iframe src="keepalive.php" style="visibility: hidden; width: 0px; height: 0px"></iframe>

an in keepalive.php you'll have:

<?php
session_start();
$_SESSION['i_am_alive'] = "something";
?>
<html>
    <head>
        <meta http-equiv="refresh" content="600" />
    </head>
    <body>OK</body>
</html>

Edit 2: Works in both Firefox and IE 8. Make sure to test in all browsers you need to support. You can include a <script>alert("something")</script> in keepalive.php during development just so you know it auto-refreshing. Do note that including the script snippet will prompt a warning in IE8 which should disappear when you remove the script part.


Sorry, but I'm pretty sure you cant do it without JS you want to manipulate the browser, PHP can't handle that.

0

精彩评论

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