Joomla authentication over two separate joomla sites

I have two Joomla 2.5 websites that are running separately. Now I want to redirect the logged in user from one page of the first website to another page on the second website.

I need a second website to find out the username and password. (I just verified that the md5-hex password of both works together). Users are logged in to both, have the same username and password in both user databases. I tried to use some php commands like "HTTPResponse :: redirect" and some joomla components to do it but it doesn't work.

+3


source to share


1 answer


Hope you can work like this.

When a user logs in to the first website and from that site, you should redirect to the second.

First, when a user visits your first site, you must save this user password and username. You will get a username with a tag $user->name

, but you will not be able to get a password for the description, so it must store that somewhere (in a protected space). Then get them for credentials and set the return url in a hidden form.

The action of this hidden form is then submitted to the second site. If a user account exists on this joomla site, you can login and redirect to the specified return url.

If not, it will not enter the second site.

you can get user information 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 the action, you can submit this form to the second joomla site. But the main thing here is the joomla form sign. If the first site marker accepts on the second joomla site, then your job is done! Otherwise, you cannot achieve this.

Hope this helps you.

+1


source







All Articles