如何阻止免费的网站托管网站强行注入PHP文件中的JavaScript,如cookie

时间:2017-06-10 11:36:11

标签: php apache webserver web-hosting

我正在使用名为“infinityfree.net”的免费虚拟主机。每当我尝试访问php web api以获取json响应时,web服务器返回html输出。 相同的php脚本在localhost上返回纯json。

有没有办法阻止/阻止虚拟主机在我的脚本中注入片段/ cookie?

TIA。

回应是这样的:

<?php
    class Persoon {
        public $voornaam = '';
        public $achternaam = '';
        protected $adres;
        protected $hobbies = array();

        public function showNaam() {
            return $this->voornaam . ' ' . $this->achternaam;
        }

        public function addHobby($hobby) {
            $this->hobbies[] = $hobby;
        }

        public function showHobbies() {
            echo implode(', ', $this->hobbies);
        }
    }

?>

2 个答案:

答案 0 :(得分:1)

我会在使用字符串函数之前和之后删除任何内容。这些免费托管通常会将代码添加到顶部。

答案 1 :(得分:0)

如果注入的代码是HTML,您可以尝试在返回的字符串上使用strip_tags。然后我会使用json_decode来解析清理后的输出。