View Full Version : Curl issue

10-30-2009, 06:28 PM

I want login with my username and password to my Joomla admin account with cURL. The code seem to be fine but still couldn't login and I ignore the reason, I create a working account for test :

Url to admin authentication page : http://www.fsr.servhome.org/administrator/?admin

Username : demo

Password : demo/

Here the php file script.php :

$fields['task'] = 'login';
$fields['option'] = 'com_login';
$fields['username'] = 'demo';
$fields['passwd'] = 'demo/';
$urlLogin = 'http://www.fsr.servhome.org/administrator/?admin';
$useragent = 'Mozilla/5.0';
$referer = $urlLogin;
$urlLogout = 'http://www.fsr.servhome.org/administrator/index.php?option=com_login&task=logout';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlLogin);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt ($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, $urlLogout);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_REFERER, $urlLogout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);

Think You

10-30-2009, 08:09 PM

I couldn't find help, seem the issue is very difficult and unique. I post the code of the login form which located in http://www.fsr.servhome.org/administrator/module/mo_login/mod_login.php. Please help me I didn't find any answer and I am working to run my first cron for more than a week and I still not able to authenticate.


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

//$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; ?>
<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">
<label for="modlgn_username"><?php echo JText::_('Username'); ?></label>
<input name="username" id="modlgn_username" type="text" class="inputbox" size="15" />

<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" />
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; ?>
<div class="button_holder">
<div class="button1">
<div class="next">
<a onclick="login.submit();">
<?php echo JText::_( 'Login' ); ?></a>

<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' ); ?>

Think You.