Doing page redirection in PHP


In php header() function is used to redirect page.

header() must be used before sending any output either by HTML, blank lines or from PHP.
Otherwise error message “header already sent” error shown.

To overcome this problem, we can use  javascript for doing page redirection as below


But if the JavaScript is disabled by the browser, then it will not work.

So we need can write a function in PHP like below,

function redirect($url=””)
if (!headers_sent()) header(“Location:$url”);
echo “<script>window.location=\”$url\”; </script>
<noscript>Automatic redirection didn’t work.<br />
<a href=\”$url\”>Click here to go to newpage.</a> </noscript>”;

Tagged with: ,
Posted in javascript, PHP

Users Sharing or Synchronisation between multiple Joomla sites

my client have two websites.. he want user of one website can access the other site too..

I have searched on google  .. I found something interesting & useful…

******   ***
I managed to make two sites work with common user base, I decided to share how it should be done step by step.

What is the solution?

  • Allows two or more Joomla! sites to have one and the same user base and sessions.
  • It could be used for other stuff (i.e. banners, sections etc.) however this is not subject of this guide. We will review only users and sessions.

What the solution is not?

  • It is not a bridge, a component, module, plugin or something like this. This is a solution on database level.
  • If you want to share components, articles etc. it is much more complicated, however not impossible. But this is not something we will review here.
  • It is not recommended to use this solution for two already existing sites, as at least one of them will either crash, or you will at least lose its user base.
  • The users in the two (or more) sites will have one and the same access rights (i.e. super admin in one will be super admin in the others as well and so on, you cannot set different rights for the different sites).


  • MySQL 5
  • PHP 5
  • Joomla! 1.5
  • The sites should share one and the same database server and the database user should have access rights to all databases in use.


Step by step:

  • Install Joomla! on localhost/site1 (or – doesn’t matter) with database name site1.
  • Install second Joomla! on localhost/site2 (or any domain) with database name site2 – it is important that the database user for both sites is one and the same.
  • Open the configuration.php files of both installations and copy the secret value ($secret = ‘somesymbolshere’;) from the configuration of site1 to the configuration to site2. So both installations should have one and the same secret key in their configuration. If you want to add even more sites, the other sites should also have the same key for secret.
  • Open phpMyAdmin of the database of site2 and execute one by one (each row is one execution) the following:
DROP TABLE `jos_users`
DROP TABLE `jos_session`
DROP TABLE `jos_stats_agents`
DROP TABLE `jos_core_acl_aro`
DROP TABLE `jos_core_acl_aro_groups`
DROP TABLE `jos_core_acl_aro_map`
DROP TABLE `jos_core_acl_sections`
DROP TABLE `jos_core_acl_groups_aro_map`

Now run the following SQL queries in the same database (if necessary replace site1 with the corresponding database name used by site1)

CREATE VIEW jos_users AS SELECT * FROM site1.jos_users
CREATE VIEW jos_session AS SELECT * FROM site1.jos_session
CREATE VIEW jos_stats_agents AS SELECT * FROM site1.jos_stats_agents
CREATE VIEW jos_core_acl_aro AS SELECT * FROM site1.jos_core_acl_aro
CREATE VIEW jos_core_acl_aro_groups AS SELECT * FROM site1.jos_core_acl_aro_groups
CREATE VIEW jos_core_acl_aro_map AS SELECT * FROM site1.jos_core_acl_aro_map
CREATE VIEW jos_core_acl_aro_sections AS SELECT * FROM site1.jos_core_acl_aro_sections
CREATE VIEW jos_core_acl_groups_aro_map AS SELECT * FROM site1.jos_core_acl_groups_aro_map

And that is all. Both sites will now have one and the same users and sessions. Adding more sites is easy, just follow the instructions here for site2 database and configuration file.
If you have existing site and you want the new one you are setting up to have all of the users of the old one, you can do it, by just imaging that your old site is site1 in this example and follow the instructions post installation.

If you have two existing sites – THIS IS NOT THE RIGHT SOLUTION FOR YOU.

Updating Joomla?
As for versions 1.5 – there is no problem. Upgrade both of your installations without any worries.
As for version 1.6 – it is hard to say yet, as it is not stable enough.

Hope you find it useful. If you have any questions, ask in that thread.

Posted in Joomla 1.5, PHP

PHP function to convert time from one timezone to another

Hi ,

I found PHP function which is very useful for time  conversion. I got this from

Some applications require finding out what the current time would be in a particular timezone. Another similar requirement would be to convert a given date/time value to a different timezone.

PHP has very powerful date handling functions and it makes the above very simple and easy. We have tried to use quite a few readymade timezone conversion classes but either they had a bug or they were too complicated. Hence we came up with our own class. The actual conversion code is only about 4 lines of code.


What it does is convert the time string argument from the source timezone into GMT time and then convert into the target timezone. This approach was far simpler than trying to directly convert from source timezone into the target timezone.


The first call to function converts 14 Sep, 2011, 02 am from the my timezone GMT+0530hrs to GMT-600hrs
here I am passing my time zone i.e. +5.30— my current time & date in format(2011-0-14 02:00:00)here
the time in 24hours– last parameter to which time zone you want to I put
the timezone of Texa-USA i.e. -6
After running the program.. I got result as ‘2011-09-14 02:00:00’.



class convert_timezone
  function convert_timezone() // Constructor of the class
  { }
  function conver_to_time($conv_fr_zon=0,$conv_fr_time="",$conv_to_zon=0)
   //echo $conv_fr_zon."<br>";
   $cd = strtotime($conv_fr_time); 
   $gmdate = date('Y-m-d H:i:s', mktime(date('H',$cd)-$conv_fr_zon,date('i',$cd),date('s',$cd),date('m',$cd),date('d',$cd),date('Y',$cd)));
   //echo $gmdate."<br>";
   $gm_timestamp = strtotime($gmdate);
   $finaldate = date('Y-m-d H:i:s', mktime(date('H',$gm_timestamp )+$conv_to_zon,date('i',$gm_timestamp ),date('s',$gm_timestamp ),date('m',$gm_timestamp ),date('d',$gm_timestamp ),date('Y',$gm_timestamp ))); 
   return $finaldate;

$resultTime = $c->conver_to_time(5.30, "2011-09-14 02:00:00", -6);
echo $resultTime;

Posted in PHP

Joomla offline Site but allow for registered users

When we are developing any new joomla site… we need to make site offline….

we can do this site->global configuration-> Site Settings —  > Site Offline to yes…

but need to open for registered user…

An override (minor hack) to Joomla 1.5 as follows:

In /includes/application.php, change value of default 23 to 18


if ($this->getCfg(‘offline’) && $user->get(‘gid’) < ’23’ ) {

$file = ‘offline’;


if ($this->getCfg(‘offline’) && $user->get(‘gid’) < ’18’ ) {

$file = ‘offline’;

This will enable registered users to view the website after login on the offline page.

This will work for joomla 1.6 also……

Posted in Joomla 1.5

How to change Joomla Admin Folder Name or Path ?

Many times people ask me, how you secure your joomla website,specially how to protect your admin side of website.So I think about to change the admin url.
By default, every joomla programmer know the default url of admin directory i.e. .

So I want to hide or just don’t want to give direct access to that url, after googling, found that changing the folder name ‘administrator’ to ‘myadmin” & change the ,

define( ‘JPATH_ADMINISTRATOR’, JPATH_ROOT.DS.’administrator’ );  to


in the ‘includes->defines.php’ & ‘administrator->includes->defines.php’ doesn create some problem in thired party component.

So finally I found another trick which work for me, is as below.

1. Create a new directory in your root directory (eg. “myadmin”)
2. Create an index.php file in your “myadmin” directory..

header(“Location: ../administrator/index.php”);

3. Add this to the beginning of index.php in real administrator folder
#administrator/index.php (modify , **do not replace**)
if ($_COOKIE[‘JoomlaAdminSession’] != “999999999”)
header(“Location: ../index.php”);
This works for me, I hope it will help others also.
Posted in Joomla 1.5

Joomla -redirect non-www URLs to www

In order to redirect all of the requests for to, you should set the appropriate rewrite rule. This can be done by adding the following lines at the beginning of the .htaccess file in your WWW folder:

RewriteCond %{HTTPS} !=on

RewriteCond %{HTTP_HOST} ^ [NC]

RewriteRule ^(.*)$$1 [L,R=301]

From now on, when someone accesses s/he will be redirected to

Using this method is safe because it should not create any redirection loops nor it should interfere with other rewrite rules.

In Joomla 1.5, we have to add above rule (code) in .htaccess file, before the joomla .htaccess rule.

so your .htaccess file look like this….

##  Can be commented out if causes errors, see notes above.

Options +FollowSymLinks
##  mod_rewrite in use
RewriteEngine On

#Custom rule(It must be before the joomla htaccess rule) for non www to www url:Start

RewriteCond %{HTTPS} !=on

RewriteCond %{HTTP_HOST} ^ [NC]

RewriteRule ^(.*)$$1 [L,R=301]

#Custom rule for non www to www url:End
########## Begin – Rewrite rules to block out some common exploits

Tagged with: ,
Posted in .htaccess, Joomla 1.5

How to enable error reporting in php

How to enable error reporting in php

This article , I copied from

In Shared Web hosting, normally we won’t be having access to the root folder php.ini file for changing any settings.

Some settings can be changed by putting another php.ini in our required folder. In this case the value will be taken from php.ini located in our folder instead of from the root folder.

But it will not be applicable for all the settings. Some settings can not be overridden.

Say for example, display of error message in the browser will be disabled by default in all production environments. But it seems putting this setting should be changed only in the php.ini file available in root folder.

But we may need to see the error message if our webpage is not working properly. We can not ask the shared web hosting company to turn on the error message. Because it will affect other people websites also.

To avoid this issue, the below code can be placed in the php file for enabling the error message display for the particular page.


ini_set("display_errors", 1);

/**Or you can write code as below**/


} else {
ini_set(‘log_errors’, ‘On’);
ini_set(‘error_log’, ROOT.DS.’tmp’.DS.’logs’.DS.’error.log’);


Posted in PHP