PHP uses the REFERER root residence to access the address for page Jump

Source: Internet
Author: User
This article mainly judges the source based on the referfer and jumps to the page to avoid page access failure and poor user experience.

This article mainly judges the source based on the referfer and jumps to the page to avoid page access failure and poor user experience.

For example, I developed a yellow page source code and transferred it to my home. I have previously set a demo program address: But now this domain name needs to be used for other sites, and what should I do if the original demo address is invalid. Then I can use php referer to determine the source. If it is from the address of the webmaster download site, I will transfer it to the site domain name.

I put the following code in index. php on this site to allow access from files.jb51.net to find my server's frequently-used software download.

You can go to the demo address on this page.

The Code is as follows:


$ ReferHost = parse_url ($ _ SERVER ['HTTP _ referer'], PHP_URL_HOST );
$ ValidDomain = 'files .jb51.net ';
$ Valid = strstr ($ referHost, $ validDomain) ==$ validDomain;
If (! Empty ($ valid )){
Echo 'script location. href = "http://s.jb51.net"; script ';
Exit;
}

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.