[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Error with PHP login form

I'm using a CMS/framework system (specfically: http://Mokoala.com/) and having trouble getting the login form to work. After entering correct credentials, it brings up the error message "Warning: Cannot modify header information - headers already sent by (output started at /home/aim/public_html/_header.php:4) in /home/aim/public_html/admin/library/com/mokoala/Cookie/CookieHolder.class.php on line 31".

Now I know this cannot be fixed without seeing all associated code (of which there's tons). But any ideas? Anything I can look at?

<?php
	if( MK_Request::getQuery('platform') === 'core' )
	{
		unset( $session->registration_details );
	}

	$user_module = MK_RecordModuleManager::getFromType('user');
	$field_module = MK_RecordModuleManager::getFromType('module_field');
	$criteria = array(
		array('field' => 'module_id', 'value' => $user_module->getId()),
		array('field' => 'name', 'value' => 'email')
	);
	
	$user_email_field = $field_module->searchRecords($criteria);
	$user_email_field = array_pop( $user_email_field );

	if( !empty( $session->registration_details ) )
	{
		$user_details = unserialize( $session->registration_details );
		$settings = array(
			'attributes' => array(
				'class' => 'narrow clear-fix standard',
				'action' => 'login.php'
			)
		);
	
		$structure = array(
			'email' => array(
				'label' => 'Email',
				'validation' => array(
					'email' => array(),
					'instance' => array(),
					'unique' => array(null, $user_email_field, $user_module)
				)
			),
			'cancel' => array(
				'type' => 'link',
				'text' => 'Cancel Login',
				'attributes' => array(
					'href' => 'login.php?platform=core'
				)
			),
		);
		
		$complete_field = array(
			'type' => 'submit',
			'attributes' => array(
				'value' => 'Complete Login'
			)
		);
	
		$form = new MK_Form($structure, $settings);
		
		$output .= '<p>Please enter your email address to finish logging in.</p>';
		if($form->isSuccessful())
		{
			$user_details['email'] = $form->getField('email')->getValue();
			$session->registration_details = serialize( $user_details );
		}
	}
	else
	{
		$settings = array(
			'attributes' => array(
				'class' => 'narrow clear-fix standard'
			)
		);
	
		$structure = array(
			'email' => array(
				'label' => 'Email',
				'validation' => array(
					'email' => array(),
					'instance' => array()
				)
			),
			'password' => array(
				'label' => 'Password',
				'validation' => array(
					'instance' => array(),
				),
				'attributes' => array(
					'type' => 'password'
				)
			),
			'login' => array(
				'type' => 'submit',
				'attributes' => array(
					'value' => 'Login'
				)
			)
		);
		
		$settings_login = array(
			'attributes' => array(
				'class' => 'narrow clear-fix standard social'
			)
		);
	
		$structure_login = array();
	
		$form = new MK_Form($structure, $settings);

		if($form->isSuccessful())
		{
			$user = MK_Authorizer::authorizeByEmailPass(
				$form->getField('email')->getValue(),
				$form->getField('password')->getValue()
			);
			
			if($user->isAuthorized())
			{
				$session->login = $user->getId();
				$cookie->set('login', $user->getId(), $config->site->user_timeout);
	
				if( !$redirect = $config->extensions->core->login_url )
				{
					$redirect = $logical_redirect;
				}
			}
			else
			{
				$form->getField('email')->getValidator()->addError('This username and password combination does not match our records. Please try again.');
			}
		}
	}
	
	$output.=$form->render();
	$output .= 'Please enter your email address and password. If you\'ve lost your login, use the <a href="forgot-pass.php">forgotten password</a> form.';

	print $output;
?>

Open in new window

0
TJOP
Asked:
TJOP
1 Solution
 
Julian HansenCommented:
The error message means that something output text before a header call was made.

This can be a coding error where output is sent to the browser at the wrong place - but sometimes it is because a file that is included has a carriage return after the closing
?> tag.

So you need to look for the header call in question and trace back through all the include files looking for either of these conditions.
0
 
TJOPAuthor Commented:
Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now