Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add session Verification in php

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report