質問

Twitter OAuthを使用してログインしようとしています。

index.php

<?php
require ("twitteroauth/twitteroauth.php");
session_start();

// The TwitterOAuth instance
$twitteroauth = new TwitterOAuth('00000000000000000', '0000000000000000000000000000000');

// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://bakasura.in/twitter/twitter_oauth.php');

// Saving them into the session
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];

// If everything goes well..
if($twitteroauth->http_code==200){
    // Let's generate the URL and redirect
    $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
    header('Location: '. $url);
} else {
    // It's a bad idea to kill the script, but we've got to know when there's an error.
    die('Something wrong happened.');
}

?>

ページが読み込まれると、[許可]ページをクリックすると、[ http://bakasura.in/twitter/twitter_oauth.php

<?php
require ("twitteroauth/twitteroauth.php");

if(!empty($_GET['oauth_verifier']) && !empty($_SESSION['oauth_token']) && !empty($_SESSION['oauth_token_secret'])){

    // We've got everything we need
    echo "Authorized";

} else {

    // Something's missing, go back to square 1
    //header('Location: twitter_login.php');
    echo "Not Authorized";

}
?> 

そしてそれは「許可されていない」と書かれています

ここで試すことができます http://bakasura.in/twitter/

役に立ちましたか?

解決

2番目のページでセッションを開始しませんでした。 session_start()に電話しない限り、セッション変数は利用できません

一部のPHPセットアップはPHP.iniを設定してセッションを自動攻撃しましたが、サーバーのセットアップを見ると、2番目のページでPHPセッションのCookieヘッダーを送信していないことがわかります。セッションは2番目のページで開始されません...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top