How can ThinkPHP3.2.3 solve the 'undefinedvariable' error?

Source: Internet
Author: User
Ip and ips, both of which indicate undefined: NOTIC: [8] Undefinedvariable: ipNOTIC: [8] Undefinedvariable: ips. Who can help you change it ~~ {Code...} ip and ips, both of which indicate undefined:

NOTIC: [8] Undefined variable: ip

NOTIC: [8] Undefined variable: ips

Who can help me change it ~~

Function Getip () {if (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {$ ip = $ _ SERVER ["HTTP_CLIENT_IP"];} if (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {// get proxy ip $ ips = explode (',', $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);} if ($ ip) {$ ips = array_unshift ($ ips, $ ip );} $ count = count ($ ips); for ($ I = 0; $ I <$ count; $ I ++) {if (! Preg_match ("/^ (10 | 172 \. 16 | 192 \. (168 )\. /I ", $ ips [$ I]) {// exclude LAN ip $ ip = $ ips [$ I]; break ;}$ tip = $ ip? $ Ip: $ _ SERVER ['remote _ ADDR ']; if ($ tip = "127.0.0.1 ") {// obtain the local real IP return $ this-> get_onlineip () ;}else {return $ tip ;}}

Reply content:

Ip address and ips, both of which are undefined:

NOTIC: [8] Undefined variable: ip

NOTIC: [8] Undefined variable: ips

Who can help me change it ~~

Function Getip () {if (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {$ ip = $ _ SERVER ["HTTP_CLIENT_IP"];} if (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {// get proxy ip $ ips = explode (',', $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);} if ($ ip) {$ ips = array_unshift ($ ips, $ ip );} $ count = count ($ ips); for ($ I = 0; $ I <$ count; $ I ++) {if (! Preg_match ("/^ (10 | 172 \. 16 | 192 \. (168 )\. /I ", $ ips [$ I]) {// exclude LAN ip $ ip = $ ips [$ I]; break ;}$ tip = $ ip? $ Ip: $ _ SERVER ['remote _ ADDR ']; if ($ tip = "127.0.0.1 ") {// obtain the local real IP return $ this-> get_onlineip () ;}else {return $ tip ;}}

If you only want to ignore this problem, lower the error reporting level, set error_reporting = E_ERROR in php. ini, or directly set it in php.error_reporting(E_Error);

ThinkPHP solves this problem. TP does not solve these problems. To solve this problem, you must first verify it through isset...

Determine whether the two variables have values. If yes, assign values. If no value exists, set it to null. Please try this.

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.