PHP - Php Session Timeout
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']; ?> Similar TutorialsHi 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?
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? 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. 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. 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. I am trying to transfer a large amount of data from a text file exported from a Microsoft Access database into a MSQL database. I have written a script in PHP to open the text file, read a line at a time, sort out the data for insertion into a new table and then insert the data into the table in the MSQL database. This works perfectly for 3 or 100+ records, so the fundamentals appear to be solid. The problem starts when I try to do all the records - about 33,500. I get: Fatal error: Maximum execution time of 30 seconds exceeded in C:\DATA\HTMLServedDocs\MusicIndex\MusicImport.php on line 40. Line 40 is the database write: $result = mysqli_query($dbc, $query); I'm not sure if the root of the error is the Web Server, the Database or something else. I am using the Abyss server, which while it is a bit clunky it is appropriate for the application. Does anyone have any ideas how to get around this problem. I could split the data up into smaller files but that is not ideal. So i have this script that connects to a game data base and it must select and make a top of some columns in data base. The thing is if the data base is offline then the script kinda blocks the website because it has no timeout option. How can i add like a $timeout=2 (in seconds) thing..so if after 2 seconds it gets no connection the script is killed Thanks in advance <?php $database_info = array( 'host' => '___', 'user' => '___', 'password' => '___', 'l2jdb' => '___' ); @mysql_connect($database_info['host'], $database_info['user'], $database_info['password']) or die(mysql_error()); @mysql_select_db($database_info['l2jdb']) or die(mysql_error()); echo "<table class=\"pvp\">"; $query = "SELECT * FROM characters WHERE accesslevel = 0 ORDER BY pvpkills DESC limit 10"; //change 10 to whatever amount you want to show on your website. $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $name = $row['char_name']; $pvpscore = $row['pvpkills']; // Inserting data into the table echo " <tr> <td width=\"110\"><strong> $name</strong></td> <td width=\"50\"><div align=\"center\">$pvpscore</div></td> </tr>"; } echo "</table>"; //closing mysql connection mysql_close(); ?> Hi I am trying to create a "User logged" function that tells the database when the user was logged in, I have heard about creating a time out for this, but dont have any idea how to do it or what it does! Any one have any ideas? Thanks Rhys I've been getting this error: Fatal error: Maximum execution time of 30 seconds exceeded in... (gives file and line number) I've cut out most of the code in the for loop to narrow it down specifically to the $i variable messing it up somehow... The 2nd part of the if statement where I try to append the $i variable to the new $row_ variable is causing it to hang like this. I want to be able to make 5 new variables... $row_1...$row_2...etc... but for some reason when I try to append the $i to it, it hangs. and throws that error eventually. Does anyone know why it does this? Any help is appreciated. Thank you! Code: [Select] for ($i=1;$i<6;$i++){ if ($row['bef_remarks' . $i] != "Description"){ $row_.$i = 1; Okay, I'm not quite sure how to state this, so I'll try my best. Is it possible to setup some kind of "after so long, it changes the state of something from 'fighting' to 'active'" query or function? What is happening is that people are fighting in my game, then choosing to just close their browser rather than quit the fight, to change the monster's state back to 'active', so other people can fight it. Does that make sense? Any thoughts or could someone point me in the right direction? Thanks!! Hi there. How do I stop a function from running it it's taking to long to proccess. For example, say after 10 seconds the code is still working I display an error message? As you can in the following code it's pulling the contents from an url or file which might take too long to load. function Tester($url); { return file_get_contents($url); } Thanks a mil I was wanting to make some kind of session timeout ability, just purely out of curiosity. I have tried going off my own theory, before looking at any tutorials, well have looked a bit but tried getting the jist and having a go myself the next day (anyways that being said), this code he Code: [Select] <?php ini_set('display_errors', 1); session_name("jeremysmith_test_session"); session_start(); $_SESSION['start_time'] = time(); if($_SESSION['start_time'] < $_SESSION['start_time'] + 500) { printf("Time out be out dated!"); } Just does not seem to want to work, is there any reason for this, that you could think of? I appreciate any replies, Jeremy. I am using this code to check if a server is running. Everything is fine when it is running, but when it's not, it takes ages for the fsockopen to fail. Is there a way to make it timeout faster? if (fsockopen($settings->survival_server, $settings->survival_port, $timeout = 0.1)){ $survival['status'] = "Up"; }else { $survival['status'] = "Down" } I have a site up where my client can enter some text in a box, and save it to a database. But the page keeps timing out. I can't get it to happen in Firefox or Chrome so it leads me to believe that its a setting in IE? This is what I have tried: set_time_limit(0) which i understand sets the time limit for the script to unlimitted. ini_set("session.use_cookies", 1); ini_set("session.cookie_lifetime", 0); Turns cookies on, and makes them last forever. session_set_cookie_params(3600); Makes a cookies last for an hour. I have tried all of these, and I have tried them in pieces. [EDIT] I do places all before session_start I have read that some of this can go into the php.ini file, but I cannot figure out exactly what I am supposed to add? Our current php.ini is the default: * CODE ******************************************************************************* register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" ; Only uncomment zend optimizer lines if your application requires Zend Optimizer support ;[Zend] ;zend_optimizer.optimization_level=15 ;zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3 ;zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3 ;zend_extension=/usr/local/Zend/lib/Optimizer-3.3.3/ZendExtensionManager.so ;zend_extension_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3/ZendExtensionManager_TS.so ; -- Be very careful to not to disable a function which might be needed! ; -- Uncomment the following lines to increase the security of your PHP site. ;disable_functions = "highlight_file,ini_alter,ini_restore,openlog,passthru, ; phpinfo, exec, system, dl, fsockopen, set_time_limit, ; popen, proc_open, proc_nice,shell_exec,show_source,symlink" * CODE ******************************************************************************* Where do I go from here? What is my next step? Thanks for taking the time to read my post, and thanks for the help! Nick Hi,
I have a heavy php page that is timing out at 30 seconds. I do not have access to change/set any ini or max_execution_time or the like. I need to find some creative workaround. First, I looked at async calls, but I'm using Yii 1.1 at the moment and it didn't look like simple to implement when I had a quick glance at that. Is it possible to load the content via ajax instead? I am having trouble resolving an error. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/s519970/public_html/header.php:27) in /home/s519970/public_html/admin/login.php on line 2 What I can gather is I can't use "header (Location: 'admin.php')" after i've used session_start(). I have tried to replace the header (Location: 'admin.php') with this: echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; I've been trying to read up on solutions but haven't been able to get it sorted. If anyone can offer some advice that would be greatly appreciated as im new to php. Code: [Select] <?php session_start(); if(isset($_SESSION['user'])) echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; ?> <div id="loginform"> <form action="dologin.php" method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login" /></td> </tr> </table> </form> </div> I have tried using require_once('yourpage.php'); before my <head></head> tags in the header document where I've specified the html information but this doesn't seem to work. I've been advised to use ob_start("ob_gzhandler"); but I am not sure how to implement this. Any advice is greatly appreciated! in this page http://maximaart.com/newscp/ i have this problem Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/maximasy/public_html/newscp/index.php:1) in /home/maximasy/public_html/newscp/index.php on line 2 my source code is <?php session_start(); include_once("config.php"); include_once("functions.php"); $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { if ($_POST['txtUserId'] === "$user" && $_POST['txtPassword'] === "$pass") { // the user id and password match, $_SESSION['basic_is_logged_in'] = true; require("main.php"); exit;?> |