2016-08-01 3 views
0

안녕하세요, 게시 요청시 세션 설정에 문제가 있습니다. 예를 들어, corectly 작업 요청을 얻을. 게시물 요청 후 리디렉션을 시도했지만이 방법도 효과가 없습니다. 내 코드 섹션이 있습니다.Silex - 게시 요청시 세션을 사용할 수 없습니다.

가 작동하지 :

$app->post(
    '/localauth', 
    'UserController::serviceLoginAuth' 
) 
->after(
    function() { 
     session_name('auth') 
     session_start(); 
    } 
); 

serviceLoginAuth에 재에만없이 사용 :

// redirect to '/authsuccess'  
$app->post('/localauth', 'UserController::serviceLoginAuth'); 
$app->get('/authsuccess', 'UserController::serviceLoginAuthSuccess'); 

내가 HTTP를 사용 각도 코드를 게시 : 도움을

 $http({ 
     url: apiConst.apiurl+'/localauth', 
     method: "POST", 
     data: $.param({ 
     login: user.login, 
     pass:user.pass 
     }), 
     headers: { 
     'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' 
     } 
    }).then(function(response){ 
     console.log(response); 
     $cookies.put('csrftoken',response.data.token); 
    }).catch(function(){ 
     console.log(err); 
    }); 

감사합니다!

+0

어떤 종류의 오류가 발생하고 있습니까? – Andy

+0

이 헤더가 없으면 http 코드 405와 옵션 오류가 발생합니다. 하지만이 헤더는이 오류를 수정하지만 게시 이후에 세션을 보낼 수 없습니다. –

답변

0

왜 silex를 사용하지 마십시오 SessionServiceProvider?

->before 대신 ->after을 사용하여 미들웨어에서 session_start를 호출하는 것이 문제 일 수 있습니다.

+0

예 이전에 아무런 영향을 미치지 않고 시도했습니다. tryed SessionServiceProvider와 동일합니다. $ app-> get()은 완벽하게 작동하지만 post()에는 몇 가지 문제가 있습니다. –

+0

그래서 $ app-> get ('/ authsuccess')에서 $ app-> post ('/ localauth')로 리디렉션하려고합니까? – Slico

+0

아니요 $ app-> post ('localauth')에서 $ app-> get ('authsuccess')으로 리디렉션하려고하며 여전히 세션을 통과 할 수 없습니다. 엄격한 'authsuccess'로 이동 한 경우에만 세션이 등록됩니다. –

관련 문제