PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, March 13, 2022

[FIXED] One php session variable causing unsetting session on redirect

 March 13, 2022     facebook-javascript-sdk, facebook-php-sdk, mysql, php, session     No comments   

Issue

I am using a combination of Javascript and PHP Facebook sdk to integrate the log in to my website (hosted on localhost).

The code after Facebook initialization and getting the access token:

if(fbidExists($profile['id']) == true)
  {

    $query = "SELECT userid AS id, username FROM users WHERE fbid = ".   $profile['id'] ;

    $login = mysqli_fetch_assoc(mysqli_query($GLOBALS['connection'], $query));

    $_SESSION['id'] = $login['id'];
    $_SESSION['username'] = $login['username'];

    header("Location: http:\\\\localhost\website\\");
    exit();
  }

Problem: After redirect there are no session variables whenever I use $login['username'], otherwise the session variables are transferring.

If I change the SQL query and replace username by any other column there is no problem and I can see the session variables after redirect. For example : $query = "SELECT userid AS id, email FROM users WHERE fbid = ". $profile['id'] ; $_SESSION['username'] = $profile['email'] creates no problem

The $_SESSION['username'] variable can be easily set through other files and creates no problem (when i use it with my own log in)

username in MySQL is of varchar type and I am using session_start() on every page and exit() after header.


Solution

Thanks for all your help. Turns out it was a problem because in the second script one on the variables was not set which was destroying the session.



Answered By - Tamanna
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing