PHP Controller redirection isn't working?

Amanda Watson
Amanda Watson used Ask the Experts™
on
Hi there,
I have set up a login process here:
http://widowspeak.com.au/index.php

If you login you go through the process etc but once you login the page it redirects to is BLANK!!

I set up the redirection to go to:

// Check to see if they're logged in, because they don't need activating!
            if ($user->get('id')) {
                  // They're already logged in, so redirect them to the home page
                  $mainframe->redirect( 'index.php?option=com_joomunity&Itemid=57' );
            }

            if ($allowUserRegistration == '0' || $userActivation == '0') {
                  JError::raiseError( 403, JText::_( 'Access Forbidden' ));
                  return;
            }

However it doesn't go to this page
http://widowspeak.com.au/index.php?option=com_joomunity&Itemid=57

as I requested?

What am I doing wrong?

I have attached the whole controller.php page that controls the login process.
I hope someone can help
<?php
/**
 * @version		$Id: controller.php 10094 2008-03-02 04:35:10Z instance $
 * @package		Joomla
 * @subpackage	Content
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */
 
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
 
jimport('joomla.application.component.controller');
 
/**
 * User Component Controller
 *
 * @package		Joomla
 * @subpackage	Weblinks
 * @since 1.5
 */
class UserController extends JController
{
	/**
	 * Method to display a view
	 *
	 * @access	public
	 * @since	1.5
	 */
	function display()
	{
		parent::display();
	}
 
	function edit()
	{
		global $mainframe, $option;
 
		$db		=& JFactory::getDBO();
		$user	=& JFactory::getUser();
 
		if ( $user->get('guest')) {
			JError::raiseError( 403, JText::_('Access Forbidden') );
			return;
		}
 
		JRequest::setVar('layout', 'form');
 
		parent::display();
	}
 
	function save()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		$user	 =& JFactory::getUser();
		$userid = JRequest::getVar( 'id', 0, 'post', 'int' );
 
		// preform security checks
		if ($user->get('id') == 0 || $userid == 0 || $userid <> $user->get('id')) {
			JError::raiseError( 403, JText::_('Access Forbidden') );
			return;
		}
 
		//clean request
		$post = JRequest::get( 'post' );
		$post['username']	= JRequest::getVar('username', '', 'post', 'username');
		$post['password']	= JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW);
		$post['password2']	= JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW);
 
		// do a password safety check
		if(strlen($post['password']) || strlen($post['password2'])) { // so that "0" can be used as password e.g.
			if($post['password'] != $post['password2']) {
				$msg	= JText::_('PASSWORDS_DO_NOT_MATCH');
				$this->setRedirect($_SERVER['HTTP_REFERER'], $msg);
				return false;
			}
		}
 
		// we don't want users to edit certain fields so we will unset them
		unset($post['gid']);
		unset($post['block']);
		unset($post['usertype']);
		unset($post['registerDate']);
		unset($post['activation']);
 
		// store data
		$model = $this->getModel('user');
 
		if ($model->store($post)) {
			$msg	= JText::_( 'Your settings have been saved.' );
		} else {
			//$msg	= JText::_( 'Error saving your settings.' );
			$msg	= $model->getError();
		}
 
		$this->setRedirect( $_SERVER['HTTP_REFERER'], $msg );
	}
 
	function cancel()
	{
		$this->setRedirect( 'index.php' );
	}
 
	function login()
	{
		// Check for request forgeries
		JRequest::checkToken('request') or jexit( 'Invalid Token' );
 
		global $mainframe;
 
		if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
			$return = base64_decode($return);
		}
 
		$options = array();
		$options['remember'] = JRequest::getBool('remember', false);
		$options['return'] = $return;
 
		$credentials = array();
		$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
		$credentials['password'] = JRequest::getString('passwd', '', 'post', JREQUEST_ALLOWRAW);
 
		//preform the login action
		$error = $mainframe->login($credentials, $options);
 
 
	}
 
	function logout()
	{
		global $mainframe;
 
		//preform the logout action
		$error = $mainframe->logout();
 
		if(!JError::isError($error))
		{
			if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
				$return = base64_decode($return);
			}
 
			// Redirect if the return url is not registration or login
			if ( $return && !( strpos( $return, 'com_user' )) ) {
				$mainframe->redirect( $return );
			}
		} else {
			parent::display();
		}
	}
 
	/**
	 * Prepares the registration form
	 * @return void
	 */
	function register()
	{
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if (!$usersConfig->get( 'allowUserRegistration' )) {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}
 
		JRequest::setVar('view', 'register');
 
		parent::display();
	}
 
	/**
	 * Save user registration and notify users and admins if required
	 * @return void
	 */
	function register_save()
	{
		global $mainframe;
 
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		// Get required system objects
		$user 		= clone(JFactory::getUser());
		$pathway 	=& $mainframe->getPathway();
		$config		=& JFactory::getConfig();
		$authorize	=& JFactory::getACL();
		$document   =& JFactory::getDocument();
 
		// If user registration is not allowed, show 403 not authorized.
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		if ($usersConfig->get('allowUserRegistration') == '0') {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}
 
		// Initialize new usertype setting
		$newUsertype = $usersConfig->get( 'new_usertype' );
		if (!$newUsertype) {
			$newUsertype = 'Registered';
		}
 
		// Bind the post array to the user object
		if (!$user->bind( JRequest::get('post'), 'usertype' )) {
			JError::raiseError( 500, $user->getError());
		}
 
		// Set some initial user values
		$user->set('id', 0);
		$user->set('usertype', '');
		$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
 
		$date =& JFactory::getDate();
		$user->set('registerDate', $date->toMySQL());
 
		// If user activation is turned on, we need to set the activation information
		$useractivation = $usersConfig->get( 'useractivation' );
		if ($useractivation == '1')
		{
			jimport('joomla.user.helper');
			$user->set('activation', md5( JUserHelper::genRandomPassword()) );
			$user->set('block', '1');
		}
 
		// If there was an error with registration, set the message and display form
		if ( !$user->save() )
		{
			JError::raiseWarning('', JText::_( $user->getError()));
			$this->register();
			return false;
		}
 
		// Send registration confirmation mail
		$password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
		$password = preg_replace('/[\x00-\x1F\x7F]/', '', $password); //Disallow control chars in the email
		UserController::_sendMail($user, $password);
 
		// Everything went fine, set relevant message depending upon user activation state and display message
		if ( $useractivation == 1 ) {
			$message  = JText::_( 'REG_COMPLETE_ACTIVATE' );
		} else {
			$message = JText::_( 'REG_COMPLETE' );
		}
 
		//TODO :: this needs to be replace by raiseMessage
		JError::raiseNotice('', $message);
		$this->register(); $this->setRedirect('index.php?option=com_content&view=article&id=46');
	}
 
	function activate()
	{
		global $mainframe;
 
		// Initialize some variables
		$db			=& JFactory::getDBO();
		$user 		=& JFactory::getUser();
		$document   =& JFactory::getDocument();
		$pathway 	=& $mainframe->getPathWay();
 
		$usersConfig = &JComponentHelper::getParams( 'com_users' );
		$userActivation			= $usersConfig->get('useractivation');
		$allowUserRegistration	= $usersConfig->get('allowUserRegistration');
 
		// Check to see if they're logged in, because they don't need activating!
		if ($user->get('id')) {
			// They're already logged in, so redirect them to the home page
			$mainframe->redirect( 'index.php?option=com_joomunity&Itemid=57' );
		}
 
		if ($allowUserRegistration == '0' || $userActivation == '0') {
			JError::raiseError( 403, JText::_( 'Access Forbidden' ));
			return;
		}
 
		// create the view
		require_once (JPATH_COMPONENT.DS.'views'.DS.'register'.DS.'view.html.php');
		$view = new UserViewRegister();
 
		$message = new stdClass();
 
		// Do we even have an activation string?
		$activation = JRequest::getVar('activation', '', '', 'alnum' );
		$activation = $db->getEscaped( $activation );
 
		if (empty( $activation ))
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));
 
			$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
			$view->assign('message', $message);
			$view->display('message');
			return;
		}
 
		// Lets activate this user
		jimport('joomla.user.helper');
		if (JUserHelper::activateUser($activation))
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' ));
 
			$message->title = JText::_( 'REG_ACTIVATE_COMPLETE_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_COMPLETE' );
		}
		else
		{
			// Page Title
			$document->setTitle( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ) );
			// Breadcrumb
			$pathway->addItem( JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' ));
 
			$message->title = JText::_( 'REG_ACTIVATE_NOT_FOUND_TITLE' );
			$message->text = JText::_( 'REG_ACTIVATE_NOT_FOUND' );
		}
 
		$view->assign('message', $message);
		$view->display('message');
	}
 
	/**
	 * Password Reset Request Method
	 *
	 * @access	public
	 */
	function requestreset()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		// Get the input
		$email		= JRequest::getVar('email', null, 'post', 'string');
 
		// Get the model
		$model = &$this->getModel('Reset');
 
		// Request a reset
		if ($model->requestReset($email) === false)
		{
			$message = JText::sprintf('PASSWORD_RESET_REQUEST_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=reset', $message);
			return false;
		}
 
		$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm');
	}
 
	/**
	 * Password Reset Confirmation Method
	 *
	 * @access	public
	 */
	function confirmreset()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		// Get the input
		$token = JRequest::getVar('token', null, 'post', 'alnum');
 
		// Get the model
		$model = &$this->getModel('Reset');
 
		// Verify the token
		if ($model->confirmReset($token) === false)
		{
			$message = JText::sprintf('PASSWORD_RESET_CONFIRMATION_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=reset&layout=confirm', $message);
			return false;
		}
 
		$this->setRedirect('index.php?option=com_user&view=reset&layout=complete');
	}
 
	/**
	 * Password Reset Completion Method
	 *
	 * @access	public
	 */
	function completereset()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		// Get the input
		$password1 = JRequest::getVar('password1', null, 'post', 'string', JREQUEST_ALLOWRAW);
		$password2 = JRequest::getVar('password2', null, 'post', 'string', JREQUEST_ALLOWRAW);
 
		// Get the model
		$model = &$this->getModel('Reset');
 
		// Reset the password
		if ($model->completeReset($password1, $password2) === false)
		{
			$message = JText::sprintf('PASSWORD_RESET_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=reset&layout=complete', $message);
			return false;
		}
 
		$message = JText::_('PASSWORD_RESET_SUCCESS');
		$this->setRedirect('index.php?option=com_user&view=login', $message);
	}
 
	/**
	 * Username Reminder Method
	 *
	 * @access	public
	 */
	function remindusername()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
 
		// Get the input
		$email = JRequest::getVar('email', null, 'post', 'string');
 
		// Get the model
		$model = &$this->getModel('Remind');
 
		// Send the reminder
		if ($model->remindUsername($email) === false)
		{
			$message = JText::sprintf('USERNAME_REMINDER_FAILED', $model->getError());
			$this->setRedirect('index.php?option=com_user&view=remind', $message);
			return false;
		}
 
		$message = JText::sprintf('USERNAME_REMINDER_SUCCESS', $email);
		$this->setRedirect('index.php?option=com_user&view=login', $message);
	}
 
	function _sendMail(&$user, $password)
	{
		global $mainframe;
 
		$db		=& JFactory::getDBO();
 
		$name 		= $user->get('name');
		$email 		= $user->get('email');
		$username 	= $user->get('username');
 
		$usersConfig 	= &JComponentHelper::getParams( 'com_users' );
		$sitename 		= $mainframe->getCfg( 'sitename' );
		$useractivation = $usersConfig->get( 'useractivation' );
		$mailfrom 		= $mainframe->getCfg( 'mailfrom' );
		$fromname 		= $mainframe->getCfg( 'fromname' );
		$siteURL		= JURI::base();
 
		$subject 	= sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject 	= html_entity_decode($subject, ENT_QUOTES);
 
		if ( $useractivation == 1 ){
			$message = sprintf ( JText::_( 'SEND_MSG_ACTIVATE' ), $name, $sitename, $siteURL."index.php?option=com_user&task=activate&activation=".$user->get('activation'), $siteURL, $username, $password);
		} else {
			$message = sprintf ( JText::_( 'SEND_MSG' ), $name, $sitename, $siteURL);
		}
 
		$message = html_entity_decode($message, ENT_QUOTES);
 
		//get all super administrator
		$query = 'SELECT name, email, sendEmail' .
				' FROM #__users' .
				' WHERE LOWER( usertype ) = "super administrator"';
		$db->setQuery( $query );
		$rows = $db->loadObjectList();
 
		// Send email to user
		if ( ! $mailfrom  || ! $fromname ) {
			$fromname = $rows[0]->name;
			$mailfrom = $rows[0]->email;
		}
 
		JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message);
 
		// Send notification to all administrators
		$subject2 = sprintf ( JText::_( 'Account details for' ), $name, $sitename);
		$subject2 = html_entity_decode($subject2, ENT_QUOTES);
 
		// get superadministrators id
		foreach ( $rows as $row )
		{
			if ($row->sendEmail)
			{
				$message2 = sprintf ( JText::_( 'SEND_MSG_ADMIN' ), $row->name, $sitename, $name, $email, $username);
				$message2 = html_entity_decode($message2, ENT_QUOTES);
				JUtility::sendMail($mailfrom, $fromname, $row->email, $subject2, $message2);
			}
		}
	}
}
?>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
A blank page usually means there was a PHP error and error reporting is supressed.

Check the error_log (apache), or the corresponding error log if you're using windows.  That will most likely tell you what is going wrong.
Amanda WatsonWeb Developer

Author

Commented:
I did something to the code which you can read about here
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24578126.html#a24892905

Did this change anything

Commented:
It could have broken it, but really, you need to check for error messages.  Do you know where to look for your error log?  If not, let me know what web server is being used (iis? apache?) Then I can let you know how to display error messages right on the page that is failing.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Amanda WatsonWeb Developer

Author

Commented:
Is this the info you need?
Apache version      2.2.6 (Unix)
PHP version      5.2.5
MySQL version      4.1.22-standard

I don't know how to check the error log, but I would love to know how

Commented:
Do you know where your server log files are?   If so, there is a file called error_log, and it will contain the error messages.

Alternatively, if you want to modify .htaccess, you can add these lines to make php display errors on the page.

php_flag display_errors on
php_value error_reporting 2047

Amanda WatsonWeb Developer

Author

Commented:
hi there,
I need a little bit more explanation.  Do I just write those two lines in the .htaccess and then how do I get the errors?

If I run the page will they just show up on the page, so everyone can see it?

Commented:
yes you just write those two lines into .htaccess.

The errors will appear on the page itself, and everyone can see it, but so will you, so you can track down where the fix is needed.   You can remove those lines (or comment them out) after you get the information you need.

Amanda WatsonWeb Developer

Author

Commented:
Hi There,
I actually found the error log.  This is what it said
[16-Jul-2009 05:36:01] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141
[20-Jul-2009 12:27:37] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141
[20-Jul-2009 12:27:50] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141

I have attached the router.php code.  It looks like this section is the offending code:
//Only an Itemid ? Get the full information from the itemid
            if(count($this->getVars()) == 1)
            {
                  $item = $menu->getItem($this->getVar('Itemid'));
                  $vars = $vars + $item->query;
            }

hmmm, so whats happening.  I am going to try to add your code also to see if I can find something specific when I log on etc.
<?php
/**
* @version		$Id: router.php 8180 2007-07-23 05:52:29Z eddieajau $
* @package		Joomla.Framework
* @subpackage	Application
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
 
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
 
/**
 * Class to create and parse routes for the site application
 *
 * @author		Johan Janssens <johan.janssens@joomla.org>
 * @package 	Joomla
 * @since		1.5
 */
class JRouterSite extends JRouter
{
	/**
	 * Class constructor
	 *
	 * @access public
	 */
	function __construct($options = array()) {
		parent::__construct($options);
	}
 
	function parse(&$uri)
	{
		$vars = array();
 
		// Get the path
		$path = $uri->getPath();
 
		//Remove the suffix
		if($this->_mode == JROUTER_MODE_SEF)
		{
			// Get the application
			$app =& JFactory::getApplication();
 
			if($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/'))
			{
				if($suffix = pathinfo($path, PATHINFO_EXTENSION))
				{
					$path = str_replace('.'.$suffix, '', $path);
					$vars['format'] = $suffix;
				}
			}
		}
 
		//Remove basepath
		$path = substr_replace($path, '', 0, strlen(JURI::base(true)));
 
		//Remove prefix
		$path = str_replace('index.php', '', $path);
 
		//Set the route
		$uri->setPath(trim($path , '/'));
 
		$vars += parent::parse($uri);
 
		return $vars;
	}
 
	function &build($url)
	{
		$uri =& parent::build($url);
 
		// Get the path data
		$route = $uri->getPath();
 
		//Add the suffix to the uri
		if($this->_mode == JROUTER_MODE_SEF && $route)
		{
			$app =& JFactory::getApplication();
 
			if($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/'))
			{
				if($format = $uri->getVar('format', 'html'))
				{
					$route .= '.'.$format;
					$uri->delVar('format');
				}
			}
 
			if($app->getCfg('sef_rewrite'))
			{
				//Transform the route
				$route = str_replace('index.php/', '', $route);
			}
		}
 
		//Add basepath to the uri
		$uri->setPath(JURI::base(true).'/'.$route);
 
		return $uri;
	}
 
	function _parseRawRoute(&$uri)
	{
		$vars   = array();
 
		$menu =& JSite::getMenu(true);
 
		//Handle an empty URL (special case)
		if(!$uri->getVar('Itemid') && !$uri->getVar('option'))
		{
			$item = $menu->getDefault();
			if(!is_object($item)) return $vars; // No default item set
 
			//Set the information in the request
			$vars = $item->query;
 
			//Get the itemid
			$vars['Itemid'] = $item->id;
 
			// Set the active menu item
			$menu->setActive($vars['Itemid']);
 
			return $vars;
		}
 
		//Get the variables from the uri
		$this->setVars($uri->getQuery(true));
 
		//Get the itemid, if it hasn't been set force it to null
		$this->setVar('Itemid', JRequest::getInt('Itemid', null));
 
		//Only an Itemid ? Get the full information from the itemid
		if(count($this->getVars()) == 1)
		{
			$item = $menu->getItem($this->getVar('Itemid'));
			$vars = $vars + $item->query;
		}
 
		// Set the active menu item
		$menu->setActive($this->getVar('Itemid'));
 
		return $vars;
	}
 
	function _parseSefRoute(&$uri)
	{
		$vars   = array();
 
		$menu  =& JSite::getMenu(true);
		$route = $uri->getPath();
 
		//Get the variables from the uri
		$vars = $uri->getQuery(true);
 
		//Handle an empty URL (special case)
		if(empty($route))
		{
 
			//If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
			if(isset($vars['option']) || isset($vars['Itemid'])) {
				return $this->_parseRawRoute($uri);
			}
 
			$item = $menu->getDefault();
 
			//Set the information in the request
			$vars = $item->query;
 
			//Get the itemid
			$vars['Itemid'] = $item->id;
 
			// Set the active menu item
			$menu->setActive($vars['Itemid']);
 
			return $vars;
		}
 
 
		/*
		 * Parse the application route
		 */
 
		if(substr($route, 0, 9) == 'component')
		{
			$segments	= explode('/', $route);
			$route      = str_replace('component/'.$segments[1], '', $route);
 
			$vars['option'] = 'com_'.$segments[1];
			$vars['Itemid'] = null;
		}
		else
		{
			//Need to reverse the array (highest sublevels first)
			$items = array_reverse($menu->getMenu());
 
			foreach ($items as $item)
			{
				$lenght = strlen($item->route); //get the lenght of the route
 
				if($lenght > 0 && strpos($route.'/', $item->route.'/') === 0 && $item->type != 'menulink')
				{
					$route   = substr($route, $lenght);
 
					$vars['Itemid'] = $item->id;
					$vars['option'] = $item->component;
					break;
				}
			}
		}
 
		// Set the active menu item
		if ( isset($vars['Itemid']) ) {
			$menu->setActive(  $vars['Itemid'] );
		}
 
		//Set the variables
		$this->setVars($vars);
 
		/*
		 * Parse the component route
		 */
		if(!empty($route) && isset($this->_vars['option']) )
		{
			$segments = explode('/', $route);
			array_shift($segments);
 
			// Handle component	route
			$component = preg_replace('/[^A-Z0-9_\.-]/i', '', $this->_vars['option']);
 
			// Use the component routing handler if it exists
			$path = JPATH_BASE.DS.'components'.DS.$component.DS.'router.php';
 
			if (file_exists($path) && count($segments))
			{
				if ($component != "com_search") { // Cheep fix on searches
					//decode the route segments
					$segments = $this->_decodeSegments($segments);
				}
 
				require_once $path;
				$function =  substr($component, 4).'ParseRoute';
				$vars =  $function($segments);
 
				$this->setVars($vars);
			}
		}
		else
		{
			//Set active menu item
			if($item =& $menu->getActive()) {
				$vars = $item->query;
			}
		}
 
		return $vars;
	}
 
	function _buildRawRoute(&$uri)
	{
	}
 
	function _buildSefRoute(&$uri)
	{
		// Get the route
		$route = $uri->getPath();
 
		// Get the query data
		$query = $uri->getQuery(true);
 
		if(!isset($query['option'])) {
			return;
		}
 
		$menu =& JSite::getMenu();
 
		/*
		 * Build the component route
		 */
		$component	= preg_replace('/[^A-Z0-9_\.-]/i', '', $query['option']);
		$tmp 		= '';
 
		// Use the component routing handler if it exists
		$path = JPATH_BASE.DS.'components'.DS.$component.DS.'router.php';
 
		// Use the custom routing handler if it exists
		if (file_exists($path) && !empty($query))
		{
			require_once $path;
			$function	= substr($component, 4).'BuildRoute';
			$parts		= $function($query);
 
			// encode the route segments
			if ($component != "com_search") { // Cheep fix on searches
				$parts = $this->_encodeSegments($parts);
			}
 
			$result = implode('/', $parts);
			$tmp	= ($result != "") ? '/'.$result : '';
		}
 
		/*
		 * Build the application route
		 */
		$built = false;
		if (isset($query['Itemid']) && !empty($query['Itemid']))
		{
			$item = $menu->getItem($query['Itemid']);
 
			if (is_object($item) && $query['option'] == $item->component) {
				$tmp = !empty($tmp) ? $item->route.'/'.$tmp : $item->route;
				$built = true;
			}
		}
 
		if(!$built) {
			$tmp = 'component/'.substr($query['option'], 4).'/'.$tmp;
		}
 
		$route .= '/'.$tmp;
 
		// Unset unneeded query information
		unset($query['Itemid']);
		unset($query['option']);
 
		//Set query again in the URI
		$uri->setQuery($query);
		$uri->setPath($route);
	}
 
	function _processParseRules(&$uri)
	{
		// Process the attached parse rules
		$vars = parent::_processParseRules($uri);
 
		// Process the pagination support
		if($this->_mode == JROUTER_MODE_SEF)
		{
			$app =& JFactory::getApplication();
 
			if($start = $uri->getVar('start'))
			{
				$uri->delVar('start');
				$vars['limitstart'] = $start;
			}
		}
 
		return $vars;
	}
 
	function _processBuildRules(&$uri)
	{
		// Make sure any menu vars are used if no others are specified
		if(($this->_mode != JROUTER_MODE_SEF) && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2)
		{
			$menu =& JSite::getMenu();
 
			// Get the active menu item
			$itemid = $uri->getVar('Itemid');
			$item   = $menu->getItem($itemid);
 
			$uri->setQuery($item->query);
			$uri->setVar('Itemid', $itemid);
		}
 
		// Process the attached build rules
		parent::_processBuildRules($uri);
 
		// Get the path data
		$route = $uri->getPath();
 
		if($this->_mode == JROUTER_MODE_SEF && $route)
		{
			$app =& JFactory::getApplication();
 
			if ($limitstart = $uri->getVar('limitstart'))
			{
				$uri->setVar('start', (int) $limitstart);
				$uri->delVar('limitstart');
			}
		}
 
		$uri->setPath($route);
	}
 
	function &_createURI($url)
	{
		//Create the URI
		$uri =& parent::_createURI($url);
 
		// Set URI defaults
		$menu =& JSite::getMenu();
 
		// Get the itemid form the URI
		$itemid = $uri->getVar('Itemid');
 
		if(is_null($itemid))
		{
			if($option = $uri->getVar('option'))
			{
				$item  = $menu->getItem($this->getVar('Itemid'));
				if(isset($item) && $item->component == $option) {
					$uri->setVar('Itemid', $item->id);
				}
			}
			else
			{
				if($option = $this->getVar('option')) {
					$uri->setVar('option', $option);
				}
 
				if($itemid = $this->getVar('Itemid')) {
					$uri->setVar('Itemid', $itemid);
				}
			}
		}
		else
		{
			if(!$uri->getVar('option'))
			{
				$item  = $menu->getItem($itemid);
				$uri->setVar('option', $item->component);
			}
		}
 
		return $uri;
	}
}

Open in new window

Amanda WatsonWeb Developer

Author

Commented:
Hi Again,
I added the two lines you mentioned into .htaccess and when I tried to go to the webpage I got this error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@widowspeak.com.au and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

Commented:
ok, it means that your hosting provider isn't allowing you to those things to .htaccess.

Without knowing the error messages, I can't go much further.

of course remove those lines from htaccess.

Perhaps you'll want to close this question, or request attention to get some fresh eyes on this one.
Richard QuadlingSenior Software Developer

Commented:
Hopefully you can confirm that line 141 is ...

$vars = $vars + $item->query;


The + wants to add 2 numbers together.

What are the types for $var and $item->query ?

Are they strings? Use $vars = $vars . $item->query;

Are they arrays? Use $vars[] = $item->query;

Are they something else?

If you are not sure, use the following debug lines (i.e. put them in, run the code, record the output, remove the lines).

var_dump($vars, $item->query);
die();

What do you get?
Amanda WatsonWeb Developer

Author

Commented:
Hi,
I am not sure what you want from line 141?
In the controller.php you can see its:
//preform the logout action
            $error = $mainframe->logout();

Anyway, where in the code that I have shown should I add the code you have written?
Should I put it at the end of the controller.php code then run the script??
Richard QuadlingSenior Software Developer

Commented:
The code in your comment http://#24908482 on this question -  line 141

The errors are in router.php

[16-Jul-2009 05:36:01] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141
[20-Jul-2009 12:27:37] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141
[20-Jul-2009 12:27:50] PHP Fatal error:  Unsupported operand types in /home/widowspe/public_html/includes/router.php on line 141

Not the controller.

Line 141 is ...

$vars = $vars + $item->query;

...

and repeat my last message at this point.


Amanda WatsonWeb Developer

Author

Commented:
Ah, sorry, YES the line at 141 is:
      $vars = $vars + $item->query;

I think they are arrays  [ ]

I have attached the whole router.php code to confirm..
<?php
/**
* @version		$Id: router.php 8180 2007-07-23 05:52:29Z eddieajau $
* @package		Joomla.Framework
* @subpackage	Application
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
 
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
 
/**
 * Class to create and parse routes for the site application
 *
 * @author		Johan Janssens <johan.janssens@joomla.org>
 * @package 	Joomla
 * @since		1.5
 */
class JRouterSite extends JRouter
{
	/**
	 * Class constructor
	 *
	 * @access public
	 */
	function __construct($options = array()) {
		parent::__construct($options);
	}
 
	function parse(&$uri)
	{
		$vars = array();
 
		// Get the path
		$path = $uri->getPath();
 
		//Remove the suffix
		if($this->_mode == JROUTER_MODE_SEF)
		{
			// Get the application
			$app =& JFactory::getApplication();
 
			if($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/'))
			{
				if($suffix = pathinfo($path, PATHINFO_EXTENSION))
				{
					$path = str_replace('.'.$suffix, '', $path);
					$vars['format'] = $suffix;
				}
			}
		}
 
		//Remove basepath
		$path = substr_replace($path, '', 0, strlen(JURI::base(true)));
 
		//Remove prefix
		$path = str_replace('index.php', '', $path);
 
		//Set the route
		$uri->setPath(trim($path , '/'));
 
		$vars += parent::parse($uri);
 
		return $vars;
	}
 
	function &build($url)
	{
		$uri =& parent::build($url);
 
		// Get the path data
		$route = $uri->getPath();
 
		//Add the suffix to the uri
		if($this->_mode == JROUTER_MODE_SEF && $route)
		{
			$app =& JFactory::getApplication();
 
			if($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/'))
			{
				if($format = $uri->getVar('format', 'html'))
				{
					$route .= '.'.$format;
					$uri->delVar('format');
				}
			}
 
			if($app->getCfg('sef_rewrite'))
			{
				//Transform the route
				$route = str_replace('index.php/', '', $route);
			}
		}
 
		//Add basepath to the uri
		$uri->setPath(JURI::base(true).'/'.$route);
 
		return $uri;
	}
 
	function _parseRawRoute(&$uri)
	{
		$vars   = array();
 
		$menu =& JSite::getMenu(true);
 
		//Handle an empty URL (special case)
		if(!$uri->getVar('Itemid') && !$uri->getVar('option'))
		{
			$item = $menu->getDefault();
			if(!is_object($item)) return $vars; // No default item set
 
			//Set the information in the request
			$vars = $item->query;
 
			//Get the itemid
			$vars['Itemid'] = $item->id;
 
			// Set the active menu item
			$menu->setActive($vars['Itemid']);
 
			return $vars;
		}
 
		//Get the variables from the uri
		$this->setVars($uri->getQuery(true));
 
		//Get the itemid, if it hasn't been set force it to null
		$this->setVar('Itemid', JRequest::getInt('Itemid', null));
 
		//Only an Itemid ? Get the full information from the itemid
		if(count($this->getVars()) == 1)
		{
			$item = $menu->getItem($this->getVar('Itemid'));
			$vars = $vars + $item->query;
		}
 
		// Set the active menu item
		$menu->setActive($this->getVar('Itemid'));
 
		return $vars;
	}
 
	function _parseSefRoute(&$uri)
	{
		$vars   = array();
 
		$menu  =& JSite::getMenu(true);
		$route = $uri->getPath();
 
		//Get the variables from the uri
		$vars = $uri->getQuery(true);
 
		//Handle an empty URL (special case)
		if(empty($route))
		{
 
			//If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
			if(isset($vars['option']) || isset($vars['Itemid'])) {
				return $this->_parseRawRoute($uri);
			}
 
			$item = $menu->getDefault();
 
			//Set the information in the request
			$vars = $item->query;
 
			//Get the itemid
			$vars['Itemid'] = $item->id;
 
			// Set the active menu item
			$menu->setActive($vars['Itemid']);
 
			return $vars;
		}
 
 
		/*
		 * Parse the application route
		 */
 
		if(substr($route, 0, 9) == 'component')
		{
			$segments	= explode('/', $route);
			$route      = str_replace('component/'.$segments[1], '', $route);
 
			$vars['option'] = 'com_'.$segments[1];
			$vars['Itemid'] = null;
		}
		else
		{
			//Need to reverse the array (highest sublevels first)
			$items = array_reverse($menu->getMenu());
 
			foreach ($items as $item)
			{
				$lenght = strlen($item->route); //get the lenght of the route
 
				if($lenght > 0 && strpos($route.'/', $item->route.'/') === 0 && $item->type != 'menulink')
				{
					$route   = substr($route, $lenght);
 
					$vars['Itemid'] = $item->id;
					$vars['option'] = $item->component;
					break;
				}
			}
		}
 
		// Set the active menu item
		if ( isset($vars['Itemid']) ) {
			$menu->setActive(  $vars['Itemid'] );
		}
 
		//Set the variables
		$this->setVars($vars);
 
		/*
		 * Parse the component route
		 */
		if(!empty($route) && isset($this->_vars['option']) )
		{
			$segments = explode('/', $route);
			array_shift($segments);
 
			// Handle component	route
			$component = preg_replace('/[^A-Z0-9_\.-]/i', '', $this->_vars['option']);
 
			// Use the component routing handler if it exists
			$path = JPATH_BASE.DS.'components'.DS.$component.DS.'router.php';
 
			if (file_exists($path) && count($segments))
			{
				if ($component != "com_search") { // Cheep fix on searches
					//decode the route segments
					$segments = $this->_decodeSegments($segments);
				}
 
				require_once $path;
				$function =  substr($component, 4).'ParseRoute';
				$vars =  $function($segments);
 
				$this->setVars($vars);
			}
		}
		else
		{
			//Set active menu item
			if($item =& $menu->getActive()) {
				$vars = $item->query;
			}
		}
 
		return $vars;
	}
 
	function _buildRawRoute(&$uri)
	{
	}
 
	function _buildSefRoute(&$uri)
	{
		// Get the route
		$route = $uri->getPath();
 
		// Get the query data
		$query = $uri->getQuery(true);
 
		if(!isset($query['option'])) {
			return;
		}
 
		$menu =& JSite::getMenu();
 
		/*
		 * Build the component route
		 */
		$component	= preg_replace('/[^A-Z0-9_\.-]/i', '', $query['option']);
		$tmp 		= '';
 
		// Use the component routing handler if it exists
		$path = JPATH_BASE.DS.'components'.DS.$component.DS.'router.php';
 
		// Use the custom routing handler if it exists
		if (file_exists($path) && !empty($query))
		{
			require_once $path;
			$function	= substr($component, 4).'BuildRoute';
			$parts		= $function($query);
 
			// encode the route segments
			if ($component != "com_search") { // Cheep fix on searches
				$parts = $this->_encodeSegments($parts);
			}
 
			$result = implode('/', $parts);
			$tmp	= ($result != "") ? '/'.$result : '';
		}
 
		/*
		 * Build the application route
		 */
		$built = false;
		if (isset($query['Itemid']) && !empty($query['Itemid']))
		{
			$item = $menu->getItem($query['Itemid']);
 
			if (is_object($item) && $query['option'] == $item->component) {
				$tmp = !empty($tmp) ? $item->route.'/'.$tmp : $item->route;
				$built = true;
			}
		}
 
		if(!$built) {
			$tmp = 'component/'.substr($query['option'], 4).'/'.$tmp;
		}
 
		$route .= '/'.$tmp;
 
		// Unset unneeded query information
		unset($query['Itemid']);
		unset($query['option']);
 
		//Set query again in the URI
		$uri->setQuery($query);
		$uri->setPath($route);
	}
 
	function _processParseRules(&$uri)
	{
		// Process the attached parse rules
		$vars = parent::_processParseRules($uri);
 
		// Process the pagination support
		if($this->_mode == JROUTER_MODE_SEF)
		{
			$app =& JFactory::getApplication();
 
			if($start = $uri->getVar('start'))
			{
				$uri->delVar('start');
				$vars['limitstart'] = $start;
			}
		}
 
		return $vars;
	}
 
	function _processBuildRules(&$uri)
	{
		// Make sure any menu vars are used if no others are specified
		if(($this->_mode != JROUTER_MODE_SEF) && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2)
		{
			$menu =& JSite::getMenu();
 
			// Get the active menu item
			$itemid = $uri->getVar('Itemid');
			$item   = $menu->getItem($itemid);
 
			$uri->setQuery($item->query);
			$uri->setVar('Itemid', $itemid);
		}
 
		// Process the attached build rules
		parent::_processBuildRules($uri);
 
		// Get the path data
		$route = $uri->getPath();
 
		if($this->_mode == JROUTER_MODE_SEF && $route)
		{
			$app =& JFactory::getApplication();
 
			if ($limitstart = $uri->getVar('limitstart'))
			{
				$uri->setVar('start', (int) $limitstart);
				$uri->delVar('limitstart');
			}
		}
 
		$uri->setPath($route);
	}
 
	function &_createURI($url)
	{
		//Create the URI
		$uri =& parent::_createURI($url);
 
		// Set URI defaults
		$menu =& JSite::getMenu();
 
		// Get the itemid form the URI
		$itemid = $uri->getVar('Itemid');
 
		if(is_null($itemid))
		{
			if($option = $uri->getVar('option'))
			{
				$item  = $menu->getItem($this->getVar('Itemid'));
				if(isset($item) && $item->component == $option) {
					$uri->setVar('Itemid', $item->id);
				}
			}
			else
			{
				if($option = $this->getVar('option')) {
					$uri->setVar('option', $option);
				}
 
				if($itemid = $this->getVar('Itemid')) {
					$uri->setVar('Itemid', $itemid);
				}
			}
		}
		else
		{
			if(!$uri->getVar('option'))
			{
				$item  = $menu->getItem($itemid);
				$uri->setVar('option', $item->component);
			}
		}
 
		return $uri;
	}
}

Open in new window

Richard QuadlingSenior Software Developer

Commented:
Now go back and read my comment #24935588 please. Specifically the last few lines dealing with running the debug code to make sure we have the right types.

The error you are seeing implies that + is NOT the appropriate way to join the values.

Saying "I think they are arrays  [ ]" is where we started really.

Or, in other words, please follow our suggestions. They are normally little steps to avoid the wrong-path-rewind problems of big changes.
Amanda WatsonWeb Developer

Author

Commented:
Ok,
I added in the lines of code you said just after the line of code in questions in router.php

//Only an Itemid ? Get the full information from the itemid
            if(count($this->getVars()) == 1)
            {
                  $item = $menu->getItem($this->getVar('Itemid'));
                  $vars = $vars + $item->query;
            }
var_dump($vars, $item->query);
die();

And when I tried to run the application I got:


array(0) { } NULL
Richard QuadlingSenior Software Developer

Commented:
Right. So, $item->query is null. You cannot add null to an array.

<?php
$array = array();
$null = null;
$array = $array + $null;

results in ...

PHP Fatal error:  Unsupported operand types ...


So it is now the case of going backwards from this point and see where the failure is.

Each of these needs to be run one at a time as the results may be long and complex.

var_dump($this->getVar('Itemid'));
var_dump($menu->getItem($this->getVar('Itemid')));

Make sure that 'Itemid' is correct and not say 'ItemID' or something different.
Amanda WatsonWeb Developer

Author

Commented:
Ok, sorry to be so ignorant with this, but can you explain  the steps.

You say each of these need to be run one at a time.....what do you mean exactly?

Senior Software Developer
Commented:
Put the first var_dump() in your code (replacing the one you've already got) and then run it. What is the result. Then replace that with the next, run it, record result.

Step by step.

We know that the point of failure is currently at line 141 and that the value of $item->query is null and I think you think it should be something different.

The problem I see though is that Joomla is a significant project.

I see (http://www.joomla.org/announcements/release-news/5243-joomla-1513-security-release-now-available.html) that there is a security release available.

Are you able to upgrade and re-test? Make a note of anything you changed and see if it is still appropriate.



As for finding the issue, you need to track back from line 141 and see what values are not being processed correctly.

What customisations have you performed?
Amanda WatsonWeb Developer

Author

Commented:
I am going to do an upgrade and retest
Amanda WatsonWeb Developer

Author

Commented:
I upgraded and it worked

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial