| Joomla login session |
|
Joomla is a great and the very powerful CMS software currently available on the market. It is open source software which means you can use it however you like. Joomla offer a great flexibility that you could do almost anything with it, ranging from online shopping cart to professional website. Because it is so powerful many people are now using it and sometimes they want to customize their login. In this article I will show you how to create you own login in Joomla instead of using the standard Jooma login. Joomla manage their own session variables so you must learn how use Joomla session and not the standard PHP $_SESSION. There are two files in the tutorial, one file is the login form where user will use this form to enter in the credential detail and the other one is to process the submission. You will also need to learn how to use Joomla session to store user’s login details in the session variable so that it can be used site wide while the user is browsing your site. In order to use Joomla classes you must first initialize Joomla framework. define( '_JEXEC', 1 ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); $mainframe =& JFactory::getApplication('site'); Once the frame work is initialised you can start using Joomla session Here is how to get session variable: $session =& JFactory::getSession(); And here is how to set session variable: $session =& JFactory::getSession(); define( '_JEXEC', 1 ); define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site'); $mainframe->initialise();
?> <html> <body>
<?php
$session =& JFactory::getSession(); $myUser = $session->get( 'myUser', 'empty' );
if($myUser != 'admin') { ?>
<H1>ITJungles</H1> <form name="login" method="post" action="loginChk.php"> <table> <tr> <td>Username</td><td><input type="text" name="txtUserid" id="txtUserid" size="14"></td> </tr> <tr> <td>Password</td><td><input type="password" name="txtPassword" id="txtPassword" size="14"></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="btnSubmit" text="Submit" value="Submit"/></td> </tr> </table> </form> <?php } else { echo 'You have logged in'; } ?> </body> </html>
LOGINCHK.PHP FILE
<?php
define( '_JEXEC', 1 ); define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site'); $mainframe->initialise();
$session =& JFactory::getSession(); $myUser = $session->get( 'myUser', 'empty' );
if($myUser != 'test_user') {
if( !empty($_POST["txtUserid"]) && !empty($_POST["txtPassword"])) { $username = $_POST["txtUserid"]; $password = $_POST["txtPassword"];
$_host="localhost"; $_user="your_user"; $_pwd="your_password"; $_db="your_database"; $handle = mysql_connect($_host,$_user,$_pwd);
if ($handle) { $errorCode=""; } else { $errorCode="Can't Open Database ".$_db." ]";}
mysql_select_db($_db); $strQuery = "SELECT * FROM iammode WHERE username='". $username ."' AND password='" . MD5($password) . "'";
$intQID = mysql_db_query($_db, $strQuery); $QueryResult = mysql_fetch_assoc($intQID); $currUserID = $QueryResult["id"]; $currUserName = $QueryResult["username"]; $currPassword = $QueryResult["password"]; mysql_close($handle);
//echo $currUserName . ' >>> ' . '' . ' test here. >>' . md5($password);
if( $currUserID == 1) { $session->set( 'myUser', $currUserName );
echo "Logged in successful as " . $currUserName . ".";
} else { echo "Logged in failed."; }
echo '<br/><br/> <h2><a href="http://www.iammode.com">Go to IAMMODE.COM</a></h2>'; } } else { echo 'logged in.'; }
?>
Comments (4)
"
|
Please can send me example of joomla login session for joomla 1.0
Thanks
John