Simple method to make background login more secure (adding session verification in php) _ PHP Tutorial

Source: Internet
Author: User
Tags myadmin
A simple method makes background logon more secure (adding session verification in php ). 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 as the background portal to register a session. Otherwise, this article will use 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:

The code is as follows:


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 ();
?>
  
[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/

Success! 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 will fail to be returned...

Related Article

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.