PHP - Implementing Timeout For User Session Inactivty In Php With Background Ajax Call
Hello All,
I have a PHP web application which will refresh itself(ajax calls connecting to the server and get the latest data) periodically. These also update the Database-based session handler class. i.e. There is NO UPDATE to the session data but the timestamp is constantly updated. Our problem is that garbage collection does not kick in as it looks at the difference between timestamp and session_gc.maxlifetime. So, if and the user is not interacting with the application. Now my question is how can I force the timeout even though refreshing happens but the user is not interacting with the application and there are "phantom" session updates made by these ajax calls. Please let me know. Thanks. Similar TutorialsHello, I've been trying this for hours now, looking at different examples and trying to change them to work for me, but with no luck... This is what I am trying to do: I have a simple form with: - 1 input field, where I can enter a number - 1 Submit Button When I enter a number into the field and click submit, I want that number to be send to the php file that is in the ajax call, then the script will take that number and run a bunch of queries and then return a new number. I want that new number to be used to call the php script via ajax again, until no number is returned, or something else is returned like the word "done" or something like that, at which point is simply makes an alert or populated a div with a message... The point is, that depending on the number entered it could take up to an hour to complete ALL the queries, so I want the script that is called to only run a fixed amount of queries at a time and then return the number it is currently at (+1), so that it can continue with the next number when it is called again. I would like to use jquery, but could also be any other way, as long as I get this to work. I already have the php script completed that needs to be called by the ajax, it returns a single number when being called. Thank you, vb Hey I was wondering is there a way I can set my sessions to timeout/end a session after a certain amount of time? Here is what I am dealing with... Code: [Select] <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> Hi Im trying to keep a session open once a user logs in for a large amount of time ( months) I have set the following in a .htaccess file php_value session.cookie_lifetime 99999999 php_value session.gc_maxlifetime 99999999 But i still lose the session and get logged out after 10 minutes or so i have created a phpinfo page and see that for these values the following is set session.cookie_lifetime 99999999( local) 0 (global) session.gc_maxlifetime 99999999 ( local) 1440 (global) What is the difference between the local and global? Any other ides why might session keeps timing out after 10 mins or so of inactivity? Ok i know the default session timeout is set to 25 minues if they are idle, but will it still timeout if the are on a constant refresh page, like if the page there on refreshes every minute will they time out after the 25 still. Hi there, I am wondering if you guys can help me make it so my session times out after a previously set time. I have researched this and found no luck. Here is my code.... Code: [Select] <?php session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; ?> Thanks in advance! I have 500 users using software I have developed, and 495 do not have a timeout problem. Our default is to timeout after 60 minutes, but one particular office times out randomly and without warning. The normal procedure is, like online banking, a pop up comes up to let them know they will be logged out in 60 seconds, or they can click continue to stay logged in.
The timer is based on JS, but on each page load a PHP function checks to see if they are timed out, and if they are, redirect them to the login page. The JS pop up never occurs, so obviously the countdown hasn't happened, but when they click on a link, they are redirected to the login page.
Since the issue only occurs in one office, it leads me to believe it is a firewall or anti-virus issue, but I'm not sure...
Anyone have any thoughts on this?
Hi: How do I set a password-protected page to time out after 20 minutes or so? I thought it was doing it on the below page, but it is not working. A tutorial I found online. Login.php Code: [Select] <form name="form1" method="post" action="myLogin.php"> <input name="myUserName" type="text" size="40" id="myUserName"> <br /><br /> <input name="myPassword" type="password" size="40" id="myPassword"> </div> <input type="submit" name="Submit" value="Login"> </form> myLogin.php Code: [Select] <?php ob_start(); // Connect to server and select database. //mysql_connect("$host", "$username", "$password")or die("cannot connect"); //mysql_select_db("$db_name")or die("cannot select DB"); // Define $myUserName and $myPassword $myUserName=$_POST['myUserName']; $myPassword=$_POST['myPassword']; // To protect MySQL injection (more detail about MySQL injection) $myUserName = stripslashes($myUserName); $myPassword = stripslashes($myPassword); $myUserName = mysql_real_escape_string($myUserName); $myPassword = mysql_real_escape_string($myPassword); $sql="SELECT * FROM myAdmins WHERE myUserName='$myUserName' and myPassword='$myPassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myUserName and $myPassword, table row must be 1 row if($count==1){ // Register $myUserName, $myPassword and redirect to file "a_Home.php" session_register("myUserName"); session_register("myPassword"); header("location:a_Home.php"); } else { echo " <html> ... </html> "; } ob_end_flush(); ?> myCheckLogin.php (added to each page to see if the person logged-in via Login.php): Code: [Select] <? session_start(); if(!session_is_registered(myUserName)){ header("location:Login.php"); } ?> Any help would be great. Thanks. When a user logs on, I authenticate them with a session. How do I use php to determine the time until the session will expire? I realize I could go into the ini file but is there a php code that can query this info and echo it back? I have a form that is very long. Sometimes the logged-in user will spend over 20 minutes on this screen and then when they hit submit, the session has already expired and they are redirected to the login screen and anything on that form is lost. Is there a way to reset the session timeout to zero everytime they either click the screen with the mouse, or type something into a form field (without submitting the form)? Not sure if this would only work with javascript or if there is php code that I would put in the beginning of the action.php that looks for whether the session has timed out and if so, add the form contents to the database first before logging them out? A php solution like that would be preferable to a javascript one. But also if the sessiopn has already expired, then the action.php script would be less secure if I put the code there because then anyone not logged in could use that page so that's probably not the solution. Best solution would be to reset the session timer whenever they click ont he screen or start typing in the form. Please help me in this guys....... I am using MVC model for my application . I am stuck with the ajax call. this is my controller application/controller/admin/index.php function getCity() { $city=$this->model->getCity(); foreach($this->city as $key => $value) { echo '<option>'.$value['name'].'</option>' ; } } this is my model application/model/admin_model.php public function getCity() { if($_POST['id']) { $cid=$_POST['id']; $sth = $this->db->prepare('SELECT id, name FROM unit WHERE cid= :cid'); $sth->execute(array(':cid' => $cid)); return $sth->fetchAll(); } } this is my view <form id="city" action="<../application/admin/regstr/" method="post"> Country <select name="country" class="country"> <option value="" selected="selected">--Select Taluka--</option> <option value="1">India</option> <option value="2">USA</option> <option value="3">China</option> </select> City <select name="city" class="city"> <option selected="selected">--Select City--</option> </select> <input type="submit" /> </form> and this is my javascript for Ajax $(document).ready(function() { $(".country").change(function() { var id=$(this).val(); var dataString = 'id='+ id; $.ajax ({ type: "POST", url: "admin/getCity", data: dataString, cache: false, success: function(html) { $(".city").html(html); } }); }); }); But I am not getting the output. I have tested it with firebug in response tab. Instead of getting only option values html code as output I am getting the whole HTML page content (i.e. content of view page admin/index.php. Please help me out. Hi
I have an AJAX call that populates a select menu based on the selection from a previous menu. All works on on desktop browser, Safari, Firefox IE etc, however when using iOS the second select menu isn't populating.
the AJAX request is as follows
<script> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getTeam(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('away-team').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function getGP(strURL) { var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('gp').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script>and the trigger for it... <select name="year" class="txtfield" onChange="getGP('find_gp_ajax.php?season='+this.value)">Any ideas why the call won't work on iOS? Hello guys is it possible to create a single php file to contain all the functions to be called via AJAX and get AJAX to call the specific function required rather than having to create individual pages for each AJAX request you need to make? Many Thanks This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=334644.0 Can anyone figure out why this works in IE and Firefox but not Safari? Any help would be great. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Concept Builders</title> <link href="_css/main.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="_css/megamenu.css" type="text/css" media="screen" /> <script src="_scripts/pagebuilder.js" type="text/javascript"></script> <script src="_scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="_scripts/jquery.nivo.slider.pack.js" type="text/javascript"></script> <script src="_scripts/jquery.easing.1.3.js" type="text/javascript"></script> <script src="js/megamenu.js" type="text/javascript"></script> <?php include 'dbconfig.php'; include 'dbopen.php'; $plan=$_GET["plan"]; $sql = "SELECT * FROM homes WHERE plan_id= '".$plan."'"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $price=$row['price']; $sqft=$row['sqft']; $beds=$row['bedrooms']; $baths=$row['baths']; $amenities=$row['amenity_1'].", ".$row['amenity_2']; } setlocale(LC_MONETARY, 'en_US'); $price=money_format('%(#6.0n', $price); $plan_details= "<table> <tr> <td width='182' class='propDetailsHeadings'>Price:</td> <td width='75'>".$price."</td> </tr> <tr> <td class='propDetailsHeadings'>SQ Feet:</td> <td>".$sqft."</td> </tr> <tr> <td class='propDetailsHeadings'>Amenities:</td> <td></td> </tr> <tr> <td>".$amenities."</td> <td></td> </tr> </table>";?> <script language="javascript" type="text/javascript"> function loadPage() { var ajaxDisplay = document.getElementById("plan_details"); ajaxDisplay.innerHTML = <?PHP echo $plan_details;?>; } </script> </head> <body onload="loadPage()"> Hey guys, I'm making an Ajax call to my database and retrieving a newsletters HTML code as the result. I then prepend it into a div area called code_content. I use some php str_replace to add some links also. When the content loads into the div, the user can then add further content to it via Ajax calls, appending articles and that. What I'm trying to figure out is how can I then retrieve all the newly edited contents of this code_content div soni can send it to my Ajax function to write to te db? Hi, This is my first post in this forum and am a PHP beginner. I have written a script in php and need to use echo to see the values of variables etc. However I dont get the output on the screen while using echo . I am using Xampp server with Apache. The startup.html file code is
<!DOCTYPE HTML>
</head>
and the test.php code is <?php
$lat = $_REQUEST['latitude'];
echo 'latitude- '.$lat . ', longitude- ' . $lon; Please help regards
Sanjish Hello, i've got some shop script which has 2 payment modules which i'd like to use for something else, the payment modules only work if the user is logged in though, i tried to make them standalone scripts but that didn't work out too well. So now i decided to go another way and just let everyone have the same session so everyone will be using the same username&password automatically. the index file looks like this: Code: [Select] <?php include('./inc/config.php'); include('./inc/functions.php'); include('./lang/'.$language.'.lng'); $id = addslashes($_REQUEST["id"]); $user = addslashes($_REQUEST["username"]); $pass = addslashes($_REQUEST["password"]); $language = strtolower($language); if(empty($id)) $id =1; $file = mysql_query('SELECT * FROM navi_'.$language.' WHERE id="'.$id.'"'); if(mysql_num_rows($file)>0) $file = mysql_fetch_array($file); else $file = mysql_fetch_array(mysql_query('SELECT * FROM navi_'.$language.' WHERE id="404"')); if(!empty($user) AND !empty($pass)) {$query = mysql_query('SELECT * FROM users WHERE username="'.$user.'" AND pass="'.md6($pass).'"'); if(mysql_num_rows($query) == 1) {$_SESSION[$session_prefix."user"] = ucfirst($user); echo'<meta http-equiv="refresh" content="0; url=index.php?id=8">';} else $error = 'Username oder Passwort ist falsch.';} include('./designe/'.$designe.'/head.tpl'); include('./designe/'.$designe.'/navi.php'); include('./designe/'.$designe.'/middle.tpl'); if(file_exists('./pages/'.$file["file"])) {echo'<h1>'.ucfirst($file["title"]).'</h1>'; include('./pages/'.$file["file"]);} if(!empty($error)) echo '<font color="red">'.$error.'</font>'; include('./designe/'.$designe.'/foot.tpl'); ?> Now i tried alot of things including adding: Code: [Select] session_start(); $_SESSION["username"] = "peter"; $_SESSION["user"] = "peter"; $_SESSION["id"] = "1"; $_SESSION["pass"] = "peter"; $_SESSION["password"] = "peter"; or Code: [Select] $id = "1"; $user = "peter"; $username = "peter"; $pass = "peter"; $password = "peter"; also a combination of both, nothing works, but i don't understand why ? Any help is appreciated. /Edit, i tried adding it to the paymentmodule .php aswell, but no luck. I have a page that functions like this:
The user begins by loading ajaxtest.php, then using a drop-down menu, selects a user, after which a DIV on ajaxtest.php is populated with the user's selction to getuser.php?q=John%Doe
Here's a visual representation of what is currently happening, along with the part I don't understand.
getuser.php consists largely of a a large HTML table which interacts through PHP with my SQL database. Several of the fields in this table are editable, and after the user changes one of these fields, he can press an "update" button, which calls an AJAX script in update.js and runs update.php, which contains all my SQL queries to update the database, without the user being redirected to this update.php page. All of this is processing perfectly - the user makes some sort of edit, hits "update", and the database gets updated without any redirection or refresh.
Here's what I can't figure out though. Once the user makes a change, and hits "update," the database updates, but the end user doesn't see those changes that he made. I can't just do a simple page refresh, because the action is taking place on getuser.php, but getuser.php is loaded inside of a #DIV on ajaxtest.php. If I use something like window.location.reload(), this just refreshes ajaxtest.php and puts the user back to the starting point of having to select a user. This is not what I want. I don't want to refresh ajaxtest.php, I want to "refresh" ajaxtest.php with getuser.php?q=John%Doe insidethe DIV on ajaxtest.php.
It seems like this is very common - several forums have this capability, where a user has a page loaded, adds a comment, and sees that comment immediately without a full page refresh. I just don't know how to do it, and I've tried at lengths to search the web for an answer with no luck.
Can someone walk me through how to do this?
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=357605.0 Where is my "Progr" return value?
This is not my first day using php but I don't code in the language that often. I don't understand why my dynamic variable is not returned in AJAX GET? Essentially, I need to give the client a simple UI so that they can copy files to a printer and I wanted to provide a little unfiltered feedback so they knew whether operation was a success. My feedback was just going to be output of exec() function though cleaned up slightly (perhaps replace line breaks with html break tags). PHP version is 5.2.17.17 and cannot be upgraded. Web Server Apache.
PHP dumbed down code:
exec("LoadZPL_PURL.bat", $output); |