国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial 請問怎么提高登錄驗證的效能

請問怎么提高登錄驗證的效能

Jun 13, 2016 pm 12:03 PM
cookie nbsp session token

請教如何提高登錄驗證的效能

本帖最后由 sky94132003 于 2014-07-25 21:02:14 編輯 最近做的一個系統

登錄是用$_COOKIE做的

會自動生成一個識別符($identifier)和驗證符($token),保存到
<br />$_COOKIE["auth"] = $identifier . ":" . $token ;<br />有做加密,在此先不提加密的事<br />


同時把
識別符($identifier)和驗證符($token)?分別保存到SQL的2個欄位

做了個function,并且在confing文件中引入運作

這樣就每一頁都會驗證

function?大約是意思是

list($identifier,?$token)?=?explode(':',?$_COOKIE['auth']);
取回$_COOKIE之前設定的
識別符($identifier)和驗證符($token)?

然后對比數據庫??這兩個值是否一模一樣

如果是正確,那就照常運作,如果不相等,就清空
setcookie('auth',?'DELETED!',?time()-1);


以上這樣做,就可以做到自動登錄的效果了

效果和驗證是可以正常使用,但問題是,大家的網站....難度驗證功能都是每一頁都要查詢一次數據庫的嗎?

有沒有什么別的方法?

基本上想到...是否做個別的timeout字段,定時清空,如果空了,才進行驗證,又重新付值一次?


腦筋有點塞了,求個思路。
------解決方案--------------------
1、驗證只發(fā)生在需要以用戶數據修改系統數據數據的頁面
2、增強的驗證必須來自不同的數據源。將?識別符和驗證符?用同一種方式傳遞,是沒有意義的,自欺欺人的。
3、如有“踢人”的需求,那么就需要時刻檢查了??墒褂米远x的?session?處理程序來完成
------解決方案--------------------
直接獲取cookie,用服務器的key解出來就可以了,不用驗證,因為若是被修改,你用服務器的key是解不出來的

比如你就存放個uid和過期時間,要是能解出來,你就直接查詢那個uid的信息,并存放到全局變量里面,解出來沒有uid,說明就是被篡改了,要重新登錄
------解決方案--------------------
引用:
先謝謝
1.?問題是怕流量大時有負載問題
2.?我寫得這么麻煩不想用SESSION,因為要做自動登錄,?應該只能用COOKIE吧?


1.負載問題我沒有實際經驗,但session的文件是hash,加了正確索引的用戶表是樹,我想前者會快一些,而且每個頁面都要查詢,似乎有些太占數據庫連接了
2.cookie和session配合著來,session負責當前登陸,存?zhèn)€cookie負責下次自動登陸唄
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Where are cookies stored? Where are cookies stored? Dec 20, 2023 pm 03:07 PM

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Where are the cookies on your computer? Where are the cookies on your computer? Dec 22, 2023 pm 03:46 PM

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to PHP Session cross-domain problem Solution to PHP Session cross-domain problem Oct 12, 2023 pm 03:00 PM

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

Where are the mobile cookies? Where are the mobile cookies? Dec 22, 2023 pm 03:40 PM

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

See all articles