0

내가 Hybridauth 사회적 로그인을 사용하고, 그리고 사용자가 페이스 북 인증에, 나는 다음과 같은 오류가 나타납니다 사용되는 매개 변수를 전달하기 때문에경고 : array_key_exists. 이 경고를 해결하는 방법?

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /hybridauth/Hybrid/thirdparty/Facebook/base_facebook.php on line 1328

내 생각 엔 (아마도 잘못)이 발생 될 수 있습니다 이유입니다 Hybridauth는 브라우저 URL에서 왔고 두 페이지 = 등록 된 & connected_with = facebook이 있습니다. Hybridauth는 두 번째 인증서 만 필요합니다 ...

실제로 인증하지만이 오류를 제거하고 싶습니다. 이 경고가 발생하는 이유는 무엇입니까? 그것을 숨길 방법이 있습니까?

/** 
    * Get the base domain used for the cookie. 
    */ 
    protected function getBaseDomain() { 
    // The base domain is stored in the metadata cookie if not we fallback 
    // to the current hostname 
    $metadata = $this->getMetadataCookie(); 
    if (array_key_exists('base_domain', $metadata) && 
     !empty($metadata['base_domain'])) { 
     return trim($metadata['base_domain'], '.'); 
    } 
    return $this->getHttpHost(); 
    } 

편집 :

/** 
    * Destroy the current session 
    */ 
    public function destroySession() { 
    $this->accessToken = null; 
    $this->signedRequest = null; 
    $this->user = null; 
    $this->clearAllPersistentData(); 

    // Javascript sets a cookie that will be used in getSignedRequest that we 
    // need to clear if we can 
    $cookie_name = $this->getSignedRequestCookieName(); 
    if (array_key_exists($cookie_name, $_COOKIE)) { 
     unset($_COOKIE[$cookie_name]); 
     if (!headers_sent()) { 
     $base_domain = $this->getBaseDomain(); 
     setcookie($cookie_name, '', 1, '/', '.'.$base_domain); 
     } else { 
     // @codeCoverageIgnoreStart 
     self::errorLog(
      'There exists a cookie that we wanted to clear that we couldn\'t '. 
      'clear because headers was already sent. Make sure to do the first '. 
      'API call before outputing anything.' 
     ); 
     // @codeCoverageIgnoreEnd 
     } 
    } 
    } 

답변

1

항상 가능성이 있기 때문에, 배열을 반환하지 않습니다 getMetadataCookie() 것 같은데 : 죄송합니다, 그것은 경고가 나오는이 코드의

오류가있는 비트이다 쿠키가 아직 설정되지 않았습니다. 그걸 사용하기 전에 실제로 배열인지 확인하는 것이 좋습니다.

if (is_array($metadata) && array_key_exists('base_domain', $metadata) && 

편집 : 당신은 같은 새로운 코드 array_key_exists()에 적용되는 것, 더 많은 코드를 추가했습니다. 쿠키가 설정되어 있지 않으면 배열에 실제로 설정되어 있는지 확실하지 않으면 먼저 확인하십시오.

+0

도움을 주셔서 감사합니다. 완전히 이해하지는 못했지만 왜 인증을 계속해야합니까? 이 경고가 내게 문제가 되는가? – gray

+1

감사합니다, 당신은 올바른 방향으로 나를 가리켰다. 나는 단지 if 절 전체를 가져 갔다. "if (array_key_exists ($ cookie_name, $ _COOKIE))"는 쿠키를 지울 필요가 있다고 말하기 때문에 " ".. 어쩌면 나아가서 맑게해라. 그러면 경고는 사라 졌을 것이다. 아마도 최고의 해결책은 아니지만 경고는 사라졌다. – gray

관련 문제