A simple method makes background logon more secure (adding session verification in php)

Source: Internet
Author: User
Tags myadmin

This document uses Joomla! The background link is used as an example to explain how to "modify" our background link to make it more secure.

Principle: Use a specific file to register a session for the background portal. Otherwise, the session fails to exit. You cannot log on to the background directly using the original background address. In this way, the diversity and changeable nature of the entry file name will provide a safer environment for your background login.

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

Purpose: register a session. The source code is as follows:

Copy codeThe Code is as follows: <? Php
Session_name ("Zjmainstay"); // The session name can be changed.
Session_start ();
$ _ SESSION ['admin _ user'] = "Y"; // The session variable name can be changed.
Session_write_close ();
?>
<Meta http-equiv = "refresh" content = "0; url = http://www.youdomain.com/administrator/">
[Html]
2. Modify the background portal file:/administrator/index. php (it can start with any CMS portal file)

Purpose: access through session control. The source code is as follows:

[Code]
Define ('_ JEXEC', 1); // Line 9 of the original file
Define ('ds', DIRECTORY_SEPARATOR); // Line 10 of the original file

// 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"; // resume session usage
Session_write_close ();
}
// Add End

Login example: http://www.youdomain.com/myadmin.php

After the carriage return will automatically jump to: http://www.youdomain.com/administrator/ (original background login address)

And directly enter: The http://www.youdomain.com/administrator/ will prompt 'Deny illegal access' and exit.

Author: Zjmainstay
Source: http://www.cnblogs.com/Zjmainstay/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.