简体   繁体   English

使用外部php脚本登录Joomla网站

[英]Logging into Joomla site using an external php script

I am trying to have a user login to a Joomla site from an external site and then be redirected to a page where only registered users can view it. 我正在尝试让用户从外部站点登录到Joomla站点,然后将其重定向到仅注册用户可以查看它的页面。 I used this script and it seems to be working somewhat. 我使用了此脚本 ,它似乎有些起作用。 I can see the user logged in via the Joomla admin panel, however when I put in a redirect at the end of the script ie. 我可以看到用户通过Joomla管理面板登录,但是当我在脚本末尾放置重定向时,即。

header('Location: registered page url');

Joomla prompts me to login in order to view the registered page. Joomla提示我登录以查看注册页面。 What am I doing wrong? 我究竟做错了什么? The original post never did discuss how to redirect the user. 原始帖子从未讨论过如何重定向用户。 Also, when I don't put the redirect in the code the browser just goes to a blank white page. 另外,当我没有在代码中放置重定向时,浏览器只会进入空白页面。 Is that normal? 那是正常的吗? Shouldn't it go to the home page of the curled site? 它不应该转到卷曲站点的主页吗?

Also note that I've tried adding a return url to the code: 另请注意,我尝试将返回URL添加到代码中:

$loginRedirectUrl = 'index.php?option=com_content&view=article&id=146&Itemid=178';
$loginRedirectUrl = base64_encode($loginRedirectUrl);  
$postfields['return'] = $loginRedirectUrl;

When I did a print_r($postfields) it returned everything filled up. 当我执行print_r($ postfields)时,它返回了所有填充的内容。 Including the encoded return url and token. 包括编码后的返回网址和令牌。 So, I'm highly confused as to why it looks like I'm logged in but the browser still somehow isn't keeping the cookies or something like that. 因此,我对为什么看起来好像已经登录却感到困惑,但浏览器仍然以某种方式没有保留Cookie或类似内容。

Cookies are not disabled. Cookies未被禁用。

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks in advance. 提前致谢。

Let's see if we can cover this one step at a time. 让我们看看是否可以一次覆盖这一步。 The bit of code in the other post just handles the logging in stuff. 另一篇文章中的代码只是处理登录内容。 If you run it unedited, then you will just end up with a blank page when it runs, so that is normal. 如果您未经编辑地运行它,那么当它运行时,您将最终得到空白页,这是正常的。

Next, if everything including the token is showing up in $postfields then the next thing I would check is to see if the Joomla admin shows a logged in session. 接下来,如果包括令牌在内的所有内容都显示在$postfields那么我接下来要检查的是Joomla管理员是否显示已登录的会话。 If it does, then the problem is in the cookie being transferred to the the browser. 如果是这样,那么问题就在于将cookie传输到浏览器。 If it isn't then it would indicate that the session was created but the login failed for some reason. 如果不是,则表明会话已创建,但由于某种原因登录失败。

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

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