English 中文(简体)
PHP IP 要求错误
原标题:PHP IP request gives error
  • 时间:2011-11-23 23:22:17
  •  标签:
  • php
  • ip
  • self

Hey, PHP Newbie here,当时我试图这样做,以获得一个给我的IP。

致命错误: 不能自食其力:当没有班级范围活跃于第14行的/home/content/56/6442856/html/unlocking/Un entitledd-4.php。

我在这里做了什么错误?

另外,请记住:这里的PHP新bie,这样可以作尽可能多的解释。

增 编

<?php 
function get_ip_address()
{
    foreach (array( HTTP_CLIENT_IP ,  HTTP_X_FORWARDED_FOR ,  HTTP_X_FORWARDED ,  HTTP_X_CLUSTER_CLIENT_IP ,  HTTP_FORWARDED_FOR ,  HTTP_FORWARDED ,  REMOTE_ADDR ) as $key)
    {
        if (array_key_exists($key, $_SERVER) === true)
        {
            foreach (explode( , , $_SERVER[$key]) as $ip)
            {
                $ip = trim($ip); // just to be safe

                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
                {
                    self::$ip = $ip; return $ip;
                }
            }
        }
    }
}

get_ip_address();
echo $ip;
?>
最佳回答
function get_ip_address()
{
    foreach (array( HTTP_CLIENT_IP ,  HTTP_X_FORWARDED_FOR ,  HTTP_X_FORWARDED ,  HTTP_X_CLUSTER_CLIENT_IP ,  HTTP_FORWARDED_FOR ,  HTTP_FORWARDED ,  REMOTE_ADDR ) as $key)
    {
        if (array_key_exists($key, $_SERVER) === true)
        {
            foreach (explode( , , $_SERVER[$key]) as $ip)
            {
                $ip = trim($ip); // just to be safe

                if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
                {
                    return $ip;
                }
            }
        }
    }
}

echo get_ip_address();

而我不知道你是否真的需要这种职能才能获得客户的IP。

echo $_SERVER[ REMOTE_ADDR ];

可能有足够的仇恨

问题回答

由于这一行,你重犯了错误:

self::$ip = $ip; return $ip;

页: 1 当你在一等舱内,并提及其固定成员之一时:

class Foo
{
    public static $my_static =  foo ;

    public function staticValue() {
        return self::$my_static; //It s correctly used here
    }
} 

页: 1 它已经涵盖其中。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签