0

There is a session which holds a data gathered from facebook. I'm trying to cache that data with Sessions. But session returns NULL in function. and yes i wrote the session_start() of course.

Here is the functions

session_start();
function startsessions(){
    $_SESSION["fbdata"] = array();
}

function getAccount($id){
    GLOBAL $facebook;
    echo $id; 
    echo gettype($_SESSION["fbdata"]["page$id"]);

    if(isset($_SESSION["fbdata"]["page$id"])){
        $result = $_SESSION["fbdata"]["page$id"];
        echo "session mode";
    }else{
        $result = $facebook->api('/'.$id);
        $result["pageimg"] = "http://graph.facebook.com/$id/picture/?width=100&height=100";
        $_SESSION["fbdata"]["page$id"] = $result; 
        echo $_SESSION["fbdata"]["page$id"];
        echo "livemode";
    }

    return $result;
}
siniradam
  • 2,727
  • 26
  • 37
  • 1
    Have you done `session_start()` on your page? – oktopus Feb 22 '13 at 09:47
  • http://www.php.net/manual/en/session.examples.basic.php – Ja͢ck Feb 22 '13 at 09:48
  • If you just enable PHP error you will get [headers already send](http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – Ron van der Heijden Feb 22 '13 at 09:48
  • Of course I've called session_start(), it's in config file. – siniradam Feb 22 '13 at 09:53
  • 1
    I'd say that only valid answer to this question is that you should work on debugging skills. Enable error reporting, correctly understanding error/warning/notification/exception, separate parts of your code and debug them separately and so on. – Leri Feb 22 '13 at 09:56
  • @PLB error_reporting(E_ALL); ini_set("display_errors", 1); all of theese are on. That is really confusing. a session is super global, it is suppose to work. in a seperate file it is works when I call the session, it returns correct data. – siniradam Feb 22 '13 at 10:00
  • 1
    @siniradam Do you call `session_start` at the very beginning of your script? – Leri Feb 22 '13 at 10:04
  • @PLB Yes. I do. I'm not newbie. – siniradam Feb 22 '13 at 10:08
  • @PLB yes you were right it was about my debuggings skills. There was a conflict with the facebook library, it was removing sessions. thanks. – siniradam Feb 22 '13 at 11:46

1 Answers1

0

Started session session_start() ?? You have to start session before you use $_SESSION

Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73