Friday, July 9, 2010

How to login in joomla site through php site...

If I entered in php site with any credentials and want to access joomla admin with the same credentials (need not to fill joomla login form)


e.g. if i have a core php site with the url http://192.168.1.201/care1/
and a joomla site with url------http://192.168.1.201/delta_strike1/administrator/

go to login function in php site: http://192.168.1.201/care1/
and set the cookies as :
setcookie("username", $username, time()+3600, "/delta_strike1/");
setcookie("passwd", $passwd, time()+3600, "/delta_strike1/");
please take care of fourth variable of set cookie function.

Now open your joomla site folder and go to \\Demo\php\delta_strike1\administrator\modules\mod_login

open mod_login.php
Note: I have copied all the code of mod_log.php and that is :-->
<?php

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.language.helper');
//$browserLang = JLanguageHelper::detectLanguage();
// forced to default
$browserLang = null;
$lang =& JFactory::getLanguage();

$languages = array();
$languages = JLanguageHelper::createLanguageList($browserLang );
array_unshift( $languages, JHTML::_('select.option',  '', JText::_( 'Default' ) ) );
$langs = JHTML::_('select.genericlist',   $languages, 'lang', ' class="inputbox"', 'value', 'text', $browserLang );
?>
<?php if(JPluginHelper::isEnabled('authentication', 'openid')) :
$lang->load( 'plg_authentication_openid', JPATH_ADMINISTRATOR );
$langScript =  'var JLanguage = {};'.
' JLanguage.WHAT_IS_OPENID = \''.JText::_( 'WHAT_IS_OPENID' ).'\';'.
' JLanguage.LOGIN_WITH_OPENID = \''.JText::_( 'LOGIN_WITH_OPENID' ).'\';'.
' JLanguage.NORMAL_LOGIN = \''.JText::_( 'NORMAL_LOGIN' ).'\';'.
' var modlogin = 1;';
$document = &JFactory::getDocument();
$document->addScriptDeclaration( $langScript );
JHTML::_('script', 'openid.js');
endif; ?>
<?php
$flag =0;
if($error = JError::getError(true)) {
$flag =1;
}
?>

<form action="<?php echo JRoute::_( 'index.php', true, $params->get('usesecure')); ?>" method="post" name="login" id="form-login" style="clear: both;">
<p id="form-login-username">
<?php if($flag==0){?>
<input name="username" id="modlgn_username" type="hidden" value="<?php echo  $_COOKIE['username'];?>" />
<input name="passwd" id="modlgn_passwd" type="hidden" value="admin"/>
<?php } ?>
<?php 
if($flag==1){?>
<label for="modlgn_username"><?php echo JText::_('Username'); ?></label>
<input name="username" id="modlgn_username" type="text" class="inputbox" size="15" />
</p>

<p id="form-login-password">
<label for="modlgn_passwd"><?php echo JText::_('Password'); ?></label>
<input name="passwd" id="modlgn_passwd" type="password" class="inputbox" size="15" />
<?php }
elseif(!isset($_COOKIE['username']) ){?>
<label for="modlgn_username"><?php echo JText::_('Username'); ?></label>
<input name="username" id="modlgn_username" type="text" class="inputbox" size="15" />
</p>

<p id="form-login-password">
<label for="modlgn_passwd"><?php echo JText::_('Password'); ?></label>
<input name="passwd" id="modlgn_passwd" type="password" class="inputbox" size="15" />
<?php } ?>
</p>
<?php
if($error = JError::getError(true)) {
echo '<p id="login-error-message">';
echo $error->get('message');
echo '<p>';
}
?>
<p id="form-login-lang" style="clear: both;">
<label for="lang"><?php echo JText::_('Language'); ?></label>
<?php echo $langs; ?>
</p>
<div class="button_holder">
<div class="button1">
<div class="next">
<a onclick="login.submit();">
<?php echo JText::_( 'Login' ); ?></a>

</div>
</div>
</div>
<div class="clr"></div>
<input type="submit" style="border: 0; padding: 0; margin: 0; width: 0px; height: 0px;" value="<?php echo JText::_( 'Login' ); ?>" />
<input type="hidden" name="option" value="com_login" />
<input type="hidden" name="task" value="login" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<?php
if($flag==1){}
elseif(isset($_COOKIE['username'])){?>
<script type="text/javascript" language="javascript">
document.login.submit();
</script>
<?php }?>

Now try it. It will work
Note: this is unsecure and totaly farji code but it will solve your purpose

4 comments:

Anand said...

nice post
very helpful for me. it solve my problem that i was try to sort out from long time .

waiting for ur next post

thanks & regard

Andrew

Anonymous said...

nice post
very helpful for me. i m looking for this code for long time.
thanks & regard
dovdov

SuperModerator said...

wah wah maja aa gaya, kya bat hai, i copied this code and it worked like a charm, thanks man, u are great !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Nitin Kumar said...

Maja aa gaya dost.

URL: http://www.eb5extell.com/

Post a Comment