简体   繁体   中英

Joomla authentication over two separate joomla sites

I have two Joomla 2.5 websites, both working separately. Now I want to redirect a logged-in user from one page of the first website to another page in second website.

I need the second website to recognize the username and password. (I've just checked that the md5-hex password of both are working together). Users are registered to both, mean have the same username and password in both user database. I've tried to use some php commands like "HTTPResponse::redirect" and some joomla components to do that but it doesn't work.

I hope you can works like this.

When the user login in first website and from this site you have to redirect to second one.

First when the user login in your first site,You should keep that user password and user name. You will get user name with $user->name object but you can't get the password for description so should keep that in some where (in secure space).Then get those to credential and set a return url in a hidden form.

Then the action of this hidden form submit to the second site.If the users account exist in that joomla site you can login and redirect to the given return url.

If not it will not login to the second site.

you can get the user details using

$user = &JFactory::getUser();

the hidden form should be like this

The action should be second site full url.
the $your_return_url should be second site url

  <form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post">
 <input type="text" tabindex="1" " value="<?php echo $user_name?>" id="username" name="username" />
<input type="password"  value="<?php echo $password?>" id="password" name="password" />
 <input type="hidden" name="return" value="<?php echo base64_encode($your_return_url); ?>" /><?php echo JHtml::_('form.token'); ?>
    </form>

Based on action you can submit this form to the second joomla site. But here one main thing is joomla form token If first sites token accept in second joomla site then your job Done! Otherwise you can't achieve this.

Hope this may help you..

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