Php prohibits access to the. PHP file directly from the address entered in the browser. _ php Tutorial

Source: Internet
Author: User
Php prohibits access to the. php file directly from the address entered in the browser ,. Php prohibits access to the. php file directly from the browser input address. this example describes how php prohibits access to the. php file directly from the browser input address. I would like to share with you how php prohibits you from accessing the. php file directly from entering the address in the browser,

This example describes how php prohibits access to the. php file directly from the address entered in the browser. Share it with you for your reference. The specific implementation method is as follows:

In general, we do not want users to directly enter the address to access some important files. we need to make some settings for this. The following summarizes some php methods that prohibit direct access to the. php file from the browser input address, which is very practical.

For example, the http://www.bkjia.com/xx.php file I don't want someone to access directly from the browser input address.

However, if you have accessed http://www.bkjia.com/xx.php from any website, you cannot connect to another address.

1. write the following code in the header of the xx. php file.

The code is as follows:

$ Fromurl = "http://www.bkjia.com/"; // jump to this address.
If ($ _ SERVER ['http _ referer'] = "")
{
Header ("Location:". $ fromurl); exit;
}


In this way, you only need to simply forge the source, and we can also perform the following operations:
2. define an identifier variable in the program

The code is as follows:

Define ('in _ SYS ', TRUE );

3. get this variable in config. php.

The code is as follows:

If (! Defined ('in _ SYS ')){
Exit ('Access prohibited ');
}


The following two methods are met in many cms.

I hope this article will help you with PHP programming.




Example: php prohibits access to the. php file directly from the address entered in the browser. I will share it with you for your reference...

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.