简体   繁体   中英

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. 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.

header('Location: registered page url');

Joomla prompts me to login in order to view the registered page. 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:

$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. 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.

Cookies are not disabled.

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. If it does, then the problem is in the cookie being transferred to the the browser. If it isn't then it would indicate that the session was created but the login failed for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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