The function $helper->getSessionFromRedirect() consistently comes back empty

It seems that I'm facing an issue where `getsessionformredirect` always returns null. The log output shows "session = " returning null. Despite looking through various threads and trying out different Facebook login example files, I haven't been able to find a solution. However, I do get logged in successfully. When I clear my cache and login via my site before going to Facebook, I find myself already logged into the platform.

Here's the code snippet:

<?php
// PHP code goes here
?>

If you need to see auto-load information:

<?php
// More PHP code for autoloading
?>

Answer №1

It appears that there was an error in the URL the page was redirecting to, but now everything is functioning correctly. The next step is to investigate why the link isn't working in Internet Explorer.

Answer №2

<?php
session_start();
// added in version 4.0.0
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// initialize app with app id and secret
FacebookSession::setDefaultApplication( '****','****' );
// login helper with redirect URI
    $helper = new FacebookRedirectLoginHelper('myurl/login_form.php' );
try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // Handle errors when Facebook returns an error
} catch( Exception $ex ) {
  // Handle validation failures or other local issues
}
error_log("session = $session \n", 3 , "C:/wamp/logs/php_error.log");
// check if we have a session
if ( isset( $session ) ) {
  // graph API request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // obtain response
  $graphObject = $response->getGraphObject();
     $fbid = $graphObject->getProperty('id');              // Retrieve Facebook ID
     $fbfullname = $graphObject->getProperty('name'); // Get full name from Facebook
    $femail = $graphObject->getProperty('email');    // Retrieve Facebook email ID
/* ---- Session Variables -----*/
    $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
    $_SESSION['EMAIL'] =  $femail;
echo( $_SESSION['FBID']);
    /* ---- Redirect after session ----*/
  header("Location: login_form.php");
} else {
  $loginUrl = $helper->getLoginUrl();
 header("Location: ".$loginUrl);
}
?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Calculate the number of posts in a monthly archive using PHP

I am trying to display the number of news articles per year and month in the following format: 2013 October (20) November (45) September (80) 2014 January (5) This is what I currently have: $sql = "SELECT YEAR(FROM_UNIXTIME(timestamp)) AS YEAR, ...

AJAX/PHP causing delays due to lag problems

I've been trying to implement an asynchronous call in my PHP script, but I keep running into the same issue: "Maximum call stack size exceeded." This is causing severe lag on my site and I suspect there might be a loop somewhere in my code that I just ...

Error message "Unexpected token" occurs when attempting to use JSON.parse on an array generated in PHP

My attempt to AJAX a JSON array is hitting a snag - when I utilize JSON.parse, an error pops up: Uncaught SyntaxError: Unexpected token Take a look at my PHP snippet: $infoJson = array('info' => array()); while($row = mysqli_fetch_array($que ...

Learn how to efficiently upload files with Ajax and Codeigniter, even without relying on Flash support

After experimenting with numerous Javascript plugins, I've reached a point where I need to seek advice. Can someone recommend the most effective method for file uploads using PHP CodeIgniter framework and Ajax? ...

Transform PNG images with transparency to JPEG format using WideImage

After users upload a photo through my script, WideImage automatically converts it to JPEG. Recently I discovered that when uploading a PNG image with a transparent background, it turns black instead. Is there a method to change this to white instead? Thi ...

What is the term for the operation of "pairing each with each"?

I am working with a matrix represented in PHP as an array: array( array('x', 'y'), // x | y array('z', 'w') // z | w ) Now, I have a second matrix also represented in a similar way (without inner a ...

PHP Social Media Plugin

My Hotel website features a Facebook registration module for users to sign up. There are two types of users on the site: regular registered users and Facebook registered users. Everything seems to be working fine so far. Users can post their own reviews, m ...

Drupal encountering memory issues due to PHP/MySQL integration

Working within a local Drupal CMS environment has been smooth sailing so far, with easy navigation and page access for viewing or editing. However, an issue arises when attempting to save changes or delete pages, leading to one of two errors popping up. E ...

What is the method for sending an object to a concealed form within php?

I am faced with a challenge involving an object named $todovalues and a form. The task at hand is to pass the entire todovalues object through the form. Here is how my form is structured - <form action="" method="post"> <input class="todobuttons ...

Issue with the PHP/AJAX (jQuery) chat function

I have developed a Chat script using PHP and jQuery, but I am concerned about the potential strain it may put on the server. Can anyone provide assistance with this? If you have an answer, please share it with me. Thank you in advance. ...

Developing a Five-Star Rating System Using PHP, MySQL, jQuery, and Ajax

I found an interesting tutorial on creating a 5-star rating system using PHP, MySQL, jQuery, and AJAX at . However, when I tried to implement it, I encountered the following errors: Notice: Undefined variable: rat in C:\xampp\htdocs\rating& ...

Issue encountered while resizing image with Code Ignitor version 1.7.3

I am currently facing an issue with resizing images using the following code. The image does not seem to resize as expected. function processHome(){ $this->load->library('image_lib'); $img_path = base_url().'img/image/50X5 ...

The PHP script retrieves the entire content of the file

Currently in the process of learning PHP, I am experimenting with connecting PHP and JavaScript using AJAX calls. Here is how my JavaScript file is set up: $.ajax({ type:"GET", url:"test.php", success:function(data) { console.log(data) ...

A step-by-step guide to integrating cloud computing and creating tokens using PHP

I am looking to create a cloud computing project using PHP. The main goal of this project is for users to store their files on a cloud server and if any unauthorized manipulations occur, the system should be able to detect and correct them. My question is ...

Issue with automatic form submission

What is the best way to automatically submit my form once the timer runs out and also when the refresh button is clicked? I have encountered an issue where every time I try to refresh the page, it prompts for user confirmation. If I click cancel, it stay ...

Transferring data from a form to PHP using AJAX

I've been struggling to get the Ajax Post Method to work after multiple attempts. <form id="search_box" method="POST" action="" > <input class="SEARCH" type="text" name="search_name" id="search_name" placeholder="Search product by name" /> ...

Which specific button is selected out of a variable number of buttons?

In my database, I store an autoincrement id along with the location and date of each trip. The piece of code below helps me display the results of my query. $mysqli = new mysqli("localhost", "root", "password", "trip"); $result = $mysqli->query("SELECT ...

The JQuery/Ajax script only loads once in the HTML document

I'm currently working on a webpage that displays data from two databases almost instantaneously. However, I've encountered an issue where my JQuery Ajax call only updates the HTML content once. HTML Code: <div class="database"> ...

Passing data in JSON format to PHP

I am having trouble sending a JSON to a PHP page using jQuery. The code I have doesn't seem to work as expected: json_data = {}; json_data.my_list = new Array (); $('#table_selected tr').each (function (i) { json_data.my_list.push ({id ...

The life cycle of a PHP request

Recently, I've found myself pondering the inner workings of the PHP VM and its request lifecycle for web applications. While I stumbled upon an informative article here, I can't shake the feeling that there's more to uncover. The idea that ...