?
Solved

How to after x seconds run a routine and redirect to other page?

Posted on 2011-03-25
3
Medium Priority
?
285 Views
Last Modified: 2012-08-14
Hi there,

i need a code in a a file msg.php, per example, after x seconds of displaying a warning, it change a value in the database and redirect the page for index.php, per example?

how to do this the best way?

Best regards,
0
Comment
Question by:AndreMarques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:meb_santoso
ID: 35216683
i don't know what's the BEST way, but you can try this :

// display warning here
 ...your routine goes here...
sleep(10); // in seconds
// change a value
....insert your own routine here (I dunno what's you're trying to change)....
// go to index.php
header('Location: http://www.example.com/index.php'); // or whatever location you need
0
 
LVL 5

Expert Comment

by:tsmgeek
ID: 35217764
if its for browsers then you need to do it diffrently

display the warning page then have a js & meta-refresh tag to redirect to another page (or same page) with extra query param to then apply the DB change
0
 
LVL 2

Accepted Solution

by:
kanchan_karjee earned 1000 total points
ID: 35231135
If this is your requirement
-- Display a warning message to user say for 10 sec.
-- Redirect the user after database updatation etc.

Then you could try using ajax.
update.php is the script where you update database.
Waiting time can be modified as requiered


<head>
<script type="text/javascript">
var redirect = false;
var waitingTime = 0;
var messageDisplayTime = 10;
function updateDBTask() {
      var xhr;
      if (window.XMLHttpRequest) {
            xhr=new XMLHttpRequest();
      } else {
            xhr=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xhr.onreadystatechange=function() {
            if (xhr.readyState==4 && xhr.status==200) {
                  redirect = true;
            }
      }
      xhr.open("GET","update.php",true);
      xhr.send();
}

function Redirect() {
      waitingTime++;
      if (redirect == true) {
            if(waitingTime >= messageDisplayTime) {
                  clearTimeout(t);
                  document.write('<scr'+'ipt type="text/javascript" >location.href="index.php"</scr'+'ipt>');
            }
      }
}
</script>
</head>
<body>
<h2>Warning message here...</h2>
</body>
<script>
updateDBTask();
var t = setInterval("Redirect()",1000);
</script>
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question