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.
当用户到达我的站点时,会为他们启动会话。在我的网站主页上有一个使用JavaScript生成子窗口的点。
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.
此子窗口进入Twitter站点以对用户进行身份验证,并将其重定向回我站点上的脚本,该脚本在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.
我发现子窗口中的PHP脚本不知道已经设置的会话和session_id,因此它启动了一个新会话,这意味着父窗口(index.php)无法访问这些会话变量。
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
oauth.php //子窗口
<?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).
当子窗口关闭并且我使用AJAX检查这样的screen_name时,它返回一个不匹配,因为子窗口oauth.php使用不同的会话(id)。
<?php session_start();
sleep(1);
if(isset($_SESSION['screen_name'])){
echo 'done';
exit;
}else{
echo session_id().$_SESSION['screen_name'];
exit;
}
?>
1 个解决方案
#1
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.
如果您使用相同的域,那么PHP应该知道会话,因为所有cookie都会根据HTTP规范发送回设置它们的域。
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 *.
请注意,www.domain.com与domain.com不同。还可以为域上的路径设置Cookie,因此请确保路径相同。也可以使用*为多个子域设置Cookie。
If you post the relevant PHP code you have, it will help.
如果您发布相关的PHP代码,它将有所帮助。
#1
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.
如果您使用相同的域,那么PHP应该知道会话,因为所有cookie都会根据HTTP规范发送回设置它们的域。
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 *.
请注意,www.domain.com与domain.com不同。还可以为域上的路径设置Cookie,因此请确保路径相同。也可以使用*为多个子域设置Cookie。
If you post the relevant PHP code you have, it will help.
如果您发布相关的PHP代码,它将有所帮助。