Method using an infinite life period session

xiaoxiao2021-03-06  44

Method using an infinite life period session

Author: Unknown Updated: Legume Source: ddvip.net Update Time: 2004.08.22 Contributor mail: tg * ddvip.com this article would not say very good, but I believe most PHPer have thought about these issues. The use of the infinite life period session joined the support for Session in PHP4.0, which is convenient for us to many programs, such as shopping carts, etc.! In many forums, session is also used to process users' logins, record username and password, so that users don't have to enter their username and password every time! However, the general session life is limited. If the user closes the browser, it cannot save the SESSION variable! So how can I achieve the permanent life of the session? Everyone knows that session is stored in the server side, obtain this user's file according to the sessionId provided by the client, and then reads the file, obtains the value of the variable, the sessionID can use the client's cookie or HTTP1.1 protocol Query_String (That is the URL of access) "?" Later partial) to transfer to the server, then the server read the session directory ... To implement the permanent life of the session, first you need to understand the PHP.INI's related settings for the session (open the php.ini file, "[Session]" section: 1, session.use_cookies: The default value is "1", representing sessionID to pass using cookies, and then use query_string to pass; 2, session.name: This is the variable name stored by sessionID, It may be cookie, or the default value is "phpsessid"; 3, session.cookie_lifetime: This represents SessionID's time in the client cookie, the default is 0, representing the browser one closed sessionID is a waste ... Because this, SESSION cannot be used forever! 4, session.gc_maxlifetime: This is the time of session data in server-side, if it exceeds this time, then session data is automatically deleted! There are still many settings, but it is related to this article, and the principles and steps of permanent session began below.

As mentioned earlier, the server reads the session data through sessionid, but the sessionID transmitted by the general browser is not there after the browser is closed, then we only need to set the sessionID and save it, no, you can have ... If you have The server's operational permissions, then set this very simple, just need to perform the following steps: Session.cookie_lifetime, "Of course, there is no infinite parameter, but 99999999 and the infinite differences); 3. Set the" session.gc_maxlifetime "setting as the" session.cookie_lifetime "; after setting, Open the editor, enter the following code: And save it to "session_check.php", open "session_check.php" with your browser See if it is "1", then close the browser, then open the browser to access "session_check.php", if "2" is displayed, then congratulations, you have succeeded; if you fail, please check your front setting. But if you don't have the server's operational permissions, then it is more troublesome, you need to rewrite the sessionID through the PHP program to achieve permanent session data saving. Check the function manual of php.net, you can see "SESSION_ID" function: If no parameters are set, then the current sessionid, if the parameters are set, the current sessionID is set to the value given ... Just use the permanent cookie plus the "session_id" function, you can save your permanent session data! But for convenience, we need to know the "session.name" of the server settings, but the general user has no permission to view the server's php.ini settings, but PHP provides a very good function "PHPINFO", using this can see almost all PHP information! PHP Related Information Display </ Title> <? phpinfo ()?> Open the editor, enter the above code, and then run this program in the browser, see the relevant information of PHP (as shown). One of the "session.name" parameters (already marked in the figure), this is the server "session.name" we need, generally "phpsessid".</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-45350.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="45350" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'gCrFgt0HQ331770QIBY7bh_2FkO_2FtlQx_2FZQ_2Bh9FuJKqq0yPkiTe98LX3nJa_2BMR2xQcdmeGj2NMaZxsTiPP'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>