The difference between getenv () and $_server in PHP

Source: Internet
Author: User

The usage differences between getenv () and $_server in PHP:

GETENV obtains the environment variable of the system, the format of the environment variable is name=value.

Syntax: string getenv (string varname);

Return value: String function type: PHP system function

Content Description

If the environment variable varname is correctly obtained, the value of the variable is returned, and the failure returns false.

The following example can get the URL of the machine where the user's browser

<?php$ip = getenv ("remote_addr");? >

$_server is the server Super global variable array with $_server[' remote_addr ') can also obtain the IP address of the client.

The difference is that getenv does not support PHP, which is run by the ISAPI mode of IIS.

"Go" solves the difference between PHP not getting the IP address ' function getenv ("REMOTE_ADDR") and $_server[' REMOTE_ADDR ']

Recently used PHP to help friends write a vote for the page, everything is smooth, installed on the discovery: the guest IP address is not able to record (failed to obtain the IP address), strange, the original local test is good ah. The local and the server is different , immediately open a space, testing, still everything is normal. After one of the problems are excluded, know that the other side is under Windows IIS, and their own tests are on Apache , most likely this reason.

Change function immediately: replace the original IP address acquisition function "getenv (" REMOTE_ADDR ")with"$_server[' remote_addr '", overwrite the update, then look at the database, the IP address has been successfully recorded Get.

Since the problem again, it is still recorded: Php to get the guest (client) IP address function getenv ("REMOTE_ADDR") and $_server[' remote_addr ', in fact, through this matter, is already very clear. Getenv ("REMOTE_ADDR") function in Apache can obtain the IP address, and in IIS, a little function, and $_server[' remote_addr '] function, both in Apache can successfully obtain the guest's IP address, It is also valid under IIS.

Excerpt from: http://wanglianghuaihua.blog.163.com/blog/static/54251531201091211275342/

The difference between getenv () and $_server in PHP

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.