Question

When a user arrives at my site, a session is started for them. There is a point where a child window is spawned using JavaScript on my sites home page.

This child window goes to Twitter site to authenticate the user and it gets redirected back to a script on my site which stores some variables in a SESSION.

I have found out that the PHP script in the child window isn't aware of the session and session_id that is set already and it therefore starts a new session which means the parent window (index.php) can not access those session variables.

I am baffled. What can I do?

Update

Here is my code, but its not my code that is the problem, its the implementation that I am having trouble with.

index.php

<?php session_start(); ?>

oauth.php //child window

<?php session_start();

$_SESSION['screen_name'] =  $twitterInfo->screen_name;

$_SESSION['profile_image_url'] = $twitterInfo->profile_image_url;

?>

When child window closes and I use AJAX to check a screen_name like so, it returns a no match as the child window oauth.php is using a different session (id).

<?php session_start();

    sleep(1);

    if(isset($_SESSION['screen_name'])){

        echo 'done';
        exit;

    }else{

        echo session_id().$_SESSION['screen_name'];
        exit;

    }
?>
Was it helpful?

Solution

If you use the same domain, then PHP should be aware of the session since all cookies are sent back to the domain that set them according to the HTTP specs.

Note that www.domain.com is a different domain then domain.com. Cookies can also be set for a path on a domain, so make sure the path is the same. Cookies can also be set for multiple sub domains using *.

If you post the relevant PHP code you have, it will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top