A versão cli do php tem várias diferenças com o cgi. Um deles é que os cabeçalhos são impressos.
Como seu código inicia uma sessão, que não existe e então verifica um determinado valor de $ _SESSION ['state'], ele sempre terminará no código header('Location: ' ...)
, que não produzirá nada, pois o cli não fazer cabeçalhos.