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
Solved

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

Posted on 2011-03-25
3
281 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
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 250 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

840 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