Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add session Verification in php

Shulou Source: shulou.com Published: 2022-06-03 05:34:04 11月17日 Update

This article is about how to add session authentication in php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Principle: register the session for the background entry through a specific file, otherwise you will fail to exit. That is, directly using the original background address will not be able to log in to the background. In this way, the diversity and changeability of entry file names will provide a more secure environment for your background login.

1. Entry file: myadmin.php (the file name can be changed at any time)

Function: register session. The source code is as follows

The copy code is as follows:

[html]

2. Modify the background entry file: / administrator/index.php (can be the beginning of any CMS entry file)

Function: use session to control entry. The source code is as follows

[code]

Define ('_ JEXEC', 1); / / original file Line 9

Define ('DS', DIRECTORY_SEPARATOR); / / original file Line 10

/ / Add

Session_name ("Zjmainstay")

Session_start ()

$ok_to_browse = ($_ SESSION ['admin_user'] = = "Y")

If (! $ok_to_browse) {

Header ("Content-type: text/html; charset=utf-8")

Exit ('deny illegal access!')

} else {

$_ SESSION ['admin_user'] = "Y"; / / continue the use of session

Session_write_close ()

}

/ / Add End

Thank you for reading! This is the end of this article on "how to add session verification in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: File entry background authentication code function content file name more source code article login good practical secure so that principle variable address Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Shulou Technology NVidia Linux