Question

i´m trying to include some code from the own server via an api / brigde / whatever...

    class ZKBrigde {

    private $_url;

    public function __construct() {
        $host = $_SERVER['HTTP_HOST'];
        $script = $_SERVER['SCRIPT_NAME'];

        $script = explode('/', $script);
        array_pop($script);
        $this->_url = "http://" . $host . implode('/', $script) . '/zk/';
    }

Here i´m looking for the main url of the target framework.

In an request im using this (example, $items is an integer):

return file_get_contents($this->_url . "brigde/acp/page/changelog/$items");

First, this has worked. In some cases if i have an error in my code, it don´t work, returns false. OK, i´ve fixed the errors.

Now, changed some code of the backend, it doesnt work. If i type the URL in my browser, i get the required result, no errors. With this now i always get the result "FALSE".

How to check what is wrong? Any hints to make it better?

(It should be an API / Brigde to my CMS)

lg., Kai

Was it helpful?

Solution

Try this:

    $this->_url = trim("http://" . $host . implode('/', $script) . '/zk/');

And try if the URL are clear and in a good format!

class ZKBrigde {

private $_url;

public function __construct() {
    $host = $_SERVER['HTTP_HOST'];
    $script = $_SERVER['SCRIPT_NAME'];

    $script = explode('/', $script);
    array_pop($script);
    $this->_url = trim("http://" . $host . implode('/', $script) . '/zk/');
    $open = open("test.txt", "w");fwrite($open, $this->_url);fclose($open);
}

Take a look in test.txt when you've tested the script.

OTHER TIPS

According to PHP's documentation if your path has special characters and you are trying to open an URI, then you need to use urlencode() function. Does your path have special characters? I'd use urlencode to be in the safe side.

http://us1.php.net/file_get_contents

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top