1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Native PHP session variables are automatically destroy after Facebbok PHP login

Discussion in 'Facebook API' started by shibly27, Jan 4, 2015.

  1. #1
    I am using facebook php sdk 4 for my application. I have add few data on $_SESSION. But those session variables are getting erased after login using FacebookRedirectLoginHelper::getLoginUrl here is code below:

    session_start();
    session_regenerate_id(true);


    define( 'ROOT', dirname( __FILE__ ) . '/' );


    require_once( ROOT . 'facebook-php-sdk-v4-4.0-dev/autoload.php' );

    use Facebook\FacebookSession;
    use Facebook\FacebookRedirectLoginHelper;

    $app_id = 'MY ID';
    $app_secret = 'MY SEC';
    $redirect_uri = 'http://myurl.com/a1.php';
    SEMrush
    // Requested permissions for the app - optional
    $permissions = array(
    'email',
    'user_location',
    'user_birthday',
    'publish_actions'
    );



    // Initialize the SDK
    FacebookSession::setDefaultApplication( $app_id, $app_secret );

    $helper = new FacebookRedirectLoginHelper( $redirect_uri );


    if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) )
    {

    $session = new FacebookSession( $_SESSION['fb_token'] );

    try {
    if ( ! $session->validate() ) {
    $session = null;
    }
    } catch ( Exception $e ) {
    // Catch any exceptions
    $session = null;
    }
    } else {

    try {
    $session = $helper->getSessionFromRedirect();
    } catch( FacebookRequestException $ex ) {


    } catch( Exception $ex ) {


    echo $ex->message;
    }
    }


    if ( isset( $session ) ) {


    $_SESSION['fb_token'] = $session->getToken();


    $session = new FacebookSession( $session->getToken() );





    }

    else {
    // No session

    $_SESSION["V_ActualData_Message"]="My Message"; **// I am not getting this one on $redirect_uri here http://myurl.com/a1.php**

    $loginUrl = $helper->getLoginUrl( $permissions );
    header('Location: ' . $loginUrl);
    exit;
    //echo '<a href="' . $loginUrl . '">Log in with FaceBook</a>';
    }
     
    shibly27, Jan 4, 2015 IP
    SEMrush