Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Are my requests messed up?
  • I made a simple Session/Auth REST API because I tried to make an SingleSignOn service for a project that I'm working on. It provides a simple function that calls the Auth::check method and translates it into a string: "1"(true) or "0"(false).
    The "API" works when I try to access it from the browser but when I build a request from other Fuel installation on another part of the project it returns false always!


    public static function request($url, $method, $data) {
    $req = \Fuel\Core\Request::forge("http://www.domain.com/path/to/api/".$url, 'curl');

    $req->set_mime_type('json');
    $req->set_method($method);
    if(!is_array($data)) {
    //Exception code
    }
    $req->set_params($data);
    return $req;
    }

    public static function isLoggedIn() {
    $r = static::request("sess", "get", array())->execute()->response()->body();
    if($r["result"] == 1)
    return true;
    return false;
    }

    These functions belong to a class inside a package.
    I'm using FuelPHP 1.6.1
  • HarroHarro
    Accepted Answer
    Sessions work with a cookie that is stored client-side, and is sent to the server on each request to maintain state. This requires a client that can handle cookies.

    cURL can do that, but you need to configure it. Look into the PHP cURL documentation on how to work with cookies, and use set_options() to pass the required options to $req.

    You can also have a look at http://fuelphp.com/docs/classes/session/advanced.html#/no-cookies on alternative ways to pass the session ID back and forth.
  • Thanks for the quick response! It was just what I needed to "open my eyes".
    Got every cookie from Input::cookie() and passed it through CURLOPT_COOKIE

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion