无法打开流:URL的权限被拒绝

时间:2016-01-30 20:16:37

标签: php

我的代码存在此问题,我收到此错误,我不确定它的含义。

Warning: file_get_contents(http://www.minecraft.net/haspaid.jsp?user=xCodr) [function.file-get-contents]: failed to open stream: Permission denied in /home/www/tripex-network.com/core/classes/Validate.php on line 60

任何人都可以向我解释如何解决它。

这是我的代码:

<?php
class Validate {
    private $_passed = false,
            $_errors = array(),
            $_db = null;

    public function __construct() {
        $host = Config::get('mysql/host');
        if(!empty($host)){
            $this->_db = DB::getInstance();
        }
    }

    public function check($source, $items = array()) {
        foreach($items as $item => $rules) {
            foreach($rules as $rule => $rule_value) {

                $value = trim($source[$item]);
                $item = escape($item);

                if($rule === 'required' && empty($value)) {
                    $this->addError("{$item} is required");
                } else if(!empty($value)) {
                    switch($rule){
                        case 'min';
                            if(strlen($value) < $rule_value) {
                                $this->addError("{$item} must be a minimum of {$rule_value} characters.");
                            }
                        break;
                        case 'max';
                            if(strlen($value) > $rule_value) {
                                $this->addError("{$item} must be a maximum of {$rule_value} characters.");
                            }                           
                        break;
                        case 'matches';
                            if($value != $source[$rule_value]) {
                                $this->addError("{$rule_value} must match {$item}.");
                            }
                        break;
                        case 'equals';
                            // TODO : Finish question/answer
                            if(strtolower($value) != "answer") {
                                $this->addError("The question was not answered correctly.");
                            }
                        break;
                        case 'agree';
                            if($value != "1") {
                                $this->addError("You must agree to our terms and conditions in order to register.");
                            }
                        break;
                        case 'unique';
                            $check = $this->_db->get($rule_value, array($item, '=', $value));
                            if($check->count()){
                                $this->addError("The username/email {$item} already exists!");
                            }
                        break;
                        case 'isvalid';
                            $username = escape($value);
                            $username = str_replace(' ', '%20', $username);
                            $check_mcUser = file_get_contents('http://www.minecraft.net/haspaid.jsp?user='.($username).'');
                            if(!$check_mcUser){
                                $this->addError("Mojang communication error");
                            } else if($check_mcUser == 'false'){
                                $this->addError("Your Minecraft name is not a valid Minecraft account.");
                            }
                        break;
                        case 'isactive';
                            $check = $this->_db->get('users', array($item, '=', $value));
                            if($check->count()) {
                                $isuseractive = $check->first()->active;
                                if($isuseractive == 0) {
                                    $this->addError("That username is inactive. Have you requested a password reset?");
                                }
                                else {}
                            }
                        break;
                        case 'isbanned';
                            $check = $this->_db->get('users', array($item, '=', $value));
                            if($check->count()) {
                                $isuserbanned = $check->first()->isbanned;
                                if($isuserbanned == 1) {
                                    $this->addError("The username {$item} is banned.");
                                }
                                else {}
                            }
                        break;
                        case 'isbannedip';
                            // check if IP is banned
                        break;
                    }
                }

            }
        }

        if(empty($this->_errors)) {
            $this->_passed = true;
        }

        return $this;

    }

    private function addError($error) {
        $this->_errors[] = $error;
    }

    public function errors() {
        return $this->_errors;
    }

    public function passed() {
        return $this->_passed;
    }

}

我正在尝试访问该网站,并说它无法打开流...

1 个答案:

答案 0 :(得分:0)

你应该对http://www.minecraft.net/haspaid.jsp?user=xCodr的file_get_contents没有问题,因为它没有任何问题地响应 - 您可以在浏览器中尝试它。

因此,似乎您的服务器中存在阻止您的安全策略。也许SELinux?

如果您有SELinux,请尝试以下操作:

  

setsebool -P httpd_can_network_connect

另见:https://stackoverflow.com/a/22829987/477572

相关链接: