[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-03-25
3
Medium Priority
?
286 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

649 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