?
Solved

if user is on page for more than 30 seconds, do something

Posted on 2011-05-02
4
Medium Priority
?
194 Views
Last Modified: 2012-05-11
i want to redirect to a page

and insert value into database

insert into table (column1) values ('timeout');
0
Comment
Question by:rgb192
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 35508340
OK, then on "initial page" you need something similar to:
window.onload=function(){
  setTimeout( "location.href='insert.php?status=exp&id=1';", 30*1000);  
}

then in insert.php
<?php
if( isset($_GET['status']) && "exp"==strval($_GET['status']) )
{
  mysql_connect("localhost","username","password") or die( mysql_error() );
  mysql_select_db("dbname") or die(mysql_error() );
  mysql_query( "insert into table (column1) values ('timeout') WHERE id=".inval($_GET['id']) ) or die( mysql_error() );
}
?>
0
 
LVL 1

Author Comment

by:rgb192
ID: 35508629
i have the form on one page.   a form that posts to itself.  Is there any way to do this on one page
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 35508727
>>a form that posts to itself.  Is there any way to do this on one page
strictly speaking you are not "POST"ing in this case. since you are redirecting via url params, then you need to use $_GET to extract the params
<?php
if( isset($_GET['status']) && "exp"==strval($_GET['status']) )
{
  mysql_connect("localhost","username","password") or die( mysql_error() );
  mysql_select_db("dbname") or die(mysql_error() );
  mysql_query( "insert into table (column1) values ('timeout') WHERE id=".inval($_GET['id']) ) or die( mysql_error() );

 //assuming you want to redirect the user to some other page after insertion
 header('otherpage.php');
 exit;
}
?>
<html>
<head>
<script>
window.onload=function(){
  setTimeout( "location.href='insert.php?status=exp&id=1';", 30*1000);  
}
</script>
</head>
<body>
..
</body>
</html>

Open in new window

0
 
LVL 1

Author Closing Comment

by:rgb192
ID: 35508987
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

578 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