简体   繁体   English

从外部站点发送脚本时的用户登录会话

[英]User login session when script sent from external site

I'm working on a bookmarklet solution with similar functionality as Instapaper (bookmarklet functionality that is, not site functionality). 我正在研究一种书签解决方案,其功能与Instapaper类似(书签功能不是网站功能)。

For my first bookmarklet version I sent the user to mysite.com/add.php?url=[url], which then did what I wanted to do (added url to the database, etc) in the backend as long as the user was logged on to my site since before (session kept alive using cookies). 对于我的第一个Booklet版本,我将用户发送到mysite.com/add.php?url=[url],然后只要用户是我,它就会在后端执行我想做的事情(向数据库添加url等)。从此登录到我的网站(会话使用cookie保持活动状态)。 The user then had to press a back button to return to the original site. 然后,用户必须按下“后退”按钮才能返回到原始站点。 This worked as intended. 这按预期工作。

Now I want to let the user remain on the original site (as the instapaper bookmarklet does) while I do the backend stuff in the background, therefore: 现在,当我在后台执行后端操作时,我想让用户保留在原始站点上(就像instapaper小书签一样),因此:
- The bookmarklet now appends a javascript function to the original site -小书签现在将javascript函数附加到原始站点
- The javascript uses a form and submits the URL to mysite.com/add.php with url as a variable (add.php is unchanged) -JavaScript使用表格并将URL用作变量将URL提交到mysite.com/add.php(add.php不变)
- I output status from add.php into an iframe that appears on the orignal site -我将add.php的状态输出到出现在原始网站上的iframe中

This works so far that the url is sent to add.php, while the user remains on the original site, and the status is printed in the iframe I temporarily display on the original site. 到目前为止,该方法一直有效,因此将URL发送到add.php,而用户仍保留在原始站点上,并且状态显示在临时显示在原始站点上的iframe中。

However, from the scripts point of view the user no longer appears to be logged on, even if he/she is when mysite.com is accessed directly. 但是,从脚本角度来看,即使直接访问mysite.com时,用户也似乎不再登录。 I'm using this login system (http://www.evolt.org/node/60384). 我正在使用此登录系统(http://www.evolt.org/node/60384)。

Can you point me in the right direction? 你能为我指出正确的方向吗? Let me know if you need more info. 让我知道您是否需要更多信息。

Thanks 谢谢

Are the cookies actually being sent to the add.php file? cookie是否实际发送到add.php文件? Have you checked with any sort of dev tools or tried `var_dump($_COOKIE)"? 您是否检查过任何开发工具或尝试过“ var_dump($ _ COOKIE)”?

What browsers have you tested it in? 您在哪些浏览器中对其进行了测试?

Off of the top of my head from what's given, I'd guess this is the browser's doing as a security precaution - otherwise any site could include an iFrame, and through JavaScript start performing actions as you on some other site without your knowledge. 从给出的内容来看,我想不到的是,这是为了安全起见,这是浏览器的工作-否则任何网站都可以包含iFrame,并通过JavaScript在您不知情的情况下像在其他网站上一样开始执行操作。

Looking around, I did find this potential workaround that specifically refers to IE7, but I have no idea if it relates to your issue as I don't know if this is only an IE issue for you. 环顾四周,我确实找到了专门针对IE7的潜在解决方法 ,但是我不知道它是否与您的问题有关,因为我不知道这是否仅是您的IE问题。

Since I get this to work in IE, but not in Firefox or Chrome, I'm leaning at the conclusion that it's due to the browsers security precautions, and that I won't get it to work by only using php session. 由于我可以在IE中使用此功能,而不能在Firefox或Chrome中使用它,因此我得出的结论是,这是由于浏览器的安全预防措施所致,而仅使用php会话就无法使其正常工作。

I've therefore come up with an alternative solution to what I want to achieve, that I want to run by you. 因此,对于要实现的目标,我想出一个替代解决方案,由您来解决。

Please comment: 请评论:

1) When a user register at my site, I create a random unique static identifier (RUSI) for that user (ie not the username or hashed pwd) 1)当用户在我的网站上注册时,我会为该用户创建一个随机的唯一静态标识符(RUSI)(即,不是用户名或散列的pwd)
2) I append this RUSI to the bookmarklet code (meaning the bookmarklet can only be added while the user is logged in to my site) 2)我将此RUSI附加到小书签代码(这意味着小书签只能在用户登录到我的网站时添加)
3) When the user press the bookmarklet, my script checks what username the RUSI corresponds to, and checks if that username is in my active_user table (that consists of all logged in uers) 3)当用户按下书签时,我的脚本检查RUSI对应的用户名,并检查该用户名是否在我的active_user表中(由所有登录的用户组成)
4) If the username exists in the active_user table, then the bookmarklet does what it supposed to do, otherwise i print "please login" or similar. 4)如果用户名存在于active_user表中,则小书签会执行其应做的操作,否则我将打印“请登录”或类似信息。

As said, please comment on this solution, as I have a hard time figuring out if this is a good or really bad approach. 如前所述,请对此解决方案发表评论,因为我很难弄清楚这是好方法还是坏方法。 The obvious down side is of course that a user who finds out another users RUSI can execute the script on his/her behalf as long as he/she is logged in. 明显的缺点当然是,只要发现其他用户RUSI,他/她就可以以他/她的名义执行脚本。

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM