Jump to content

smf login redirect


semaj4712

Recommended Posts

Hey hey, an answer I know!!

 

Check this page out:

 

http://docs.simplemachines.org/index.php?topic=789.msg1688#msg1688

 

Basically, you should have already included SSI.php at the very top of your PHP file, then used the ssi_login() function from the login.  To redirect them, all you do is, right beneath your SSI include, you set the session variable for the redirect:

 

<?php
require_once("forums/SSI.php");
$_SESSION['login_url'] = 'http://url.to.login.page/';
$_SESSION['logout_url'] = 'http://url.to.logout.page/';
?>

 

Above is the exact code I use for my site.  And it works fine.

Link to comment
Share on other sites

um theres sum stuff before it and after it

 

<? if (!defined('_VALID_MOS'))
die('Direct Access to this location is not allowed.');

global $smf_path, $bridge_reg, $maintenance, $sourcedir, $context, $user, $mosConfig_live_site, $mosConfig_db, $mosConfig_dbprefix, $synch_lang;

// Get the configuration.  This will tell Mambo where SMF is, and some integration settings
$database->setQuery("
			SELECT `variable`, `value1`
			FROM #__smf_config
			");
$variables = $database->loadAssocList();

foreach ($variables as $variable){
	$variable_name = $variable['variable'];
	$$variable_name = $variable['value1'];
}

//This entire structure only needs to be executed on non-SMF pages.
if (!defined('SMF_INTEGRATION_SETTINGS')){	
define('SMF_INTEGRATION_SETTINGS', serialize(array(
	'integrate_pre_load' => 'integrate_pre_load',
)));

function integrate_pre_load () {

global $lang, $language, $mosConfig_lang, $synch_lang, $smf_lang, $smf_path;

$language_conversion = array(
						'aa' => 'afar',
						'ab' => 'abkhaz',
						'ae' => 'avestan',
						'af' => 'afrikaans',
						'ak' => 'akan',
						'ar' => 'arabic',
						'am' => 'amharic',
						'an' => 'aragonese',
						'as' => 'assamese',
						'av' => 'avaric',
						'ay' => 'aymara',
						'az' => 'azerbaijani',
						'ba' => 'bashkir',
						'be' => 'belarusian',
						'bg' => 'bulgarian',
						'bh' => 'bihari',
						'bi' => 'bislama',
						'bm' => 'bambara',
						'bn' => 'bangla',
						'br' => 'breton',
						'bs' => 'bosnian',
						'cr' => 'cree',
						'da' => 'danish',
						'de' => 'german',
						'dv' => 'divehi',
						'dz' => 'dzongkha',
						'en' => 'english',
						'fa' => 'farsi',
						'es' => 'spanish',
						'fr' => 'french',
						'gn' => 'guarani',
						'hr' => 'croatian',
						'hu' => 'hungarian',
						'hy' => 'armenian',
						'it' => 'italian',
						'kr' => 'kanuri',
						'ml' => 'malayalam',
						'mo' => 'moldovan',
						'nb' => 'bokm&#229;l',
						'nl' => 'dutch',
						'nn' => 'nynorsk',
						'no' => 'norsk',
						'pl' => 'polish',
						'pt' => 'portuguese',
						'sh' => 'serbo-croatian',
						'sr' => 'serbian',
						'sq' => 'albanian',
						'tg' => 'tajik',
						'th' => 'thai',
						'tr' => 'turkish',
						'iu' => 'inuktitut',
						'za' => 'zhuang',
						'zh' => 'chinese',
						'zu' => 'zulu',
						);
	if(isset($mosConfig_lang) && $synch_lang == 'true'){

		if (isset($_COOKIE['mbfcookie']) || isset($_REQUEST['lang'])){
          
			if (isset($_COOKIE['mbfcookie']['lang'])){ 
				if (isset($language_conversion[$_COOKIE['mbfcookie']['lang']]) && file_exists($smf_path . '/Themes/default/languages/index.' . $language_conversion[$_COOKIE['mbfcookie']['lang']] . '.php'))
					$GLOBALS['language'] = $language_conversion[$_COOKIE['mbfcookie']['lang']];
				else if (isset($language_conversion[$_COOKIE['mbfcookie']['lang']]) && file_exists($smf_path . '/Themes/default/languages/index.' . $language_conversion[$_COOKIE['mbfcookie']['lang']] . '-utf8.php'))
					$GLOBALS['language'] = $language_conversion[$_COOKIE['mbfcookie']['lang']] . '-utf8';
				else if (file_exists($smf_path . '/Themes/default/languages/index.' . $_COOKIE['mbfcookie']['lang'] . '.php'))
					$GLOBALS['language'] = $_COOKIE['mbfcookie']['lang'];
				else if (file_exists($smf_path . '/Themes/default/languages/index.' . $_COOKIE['mbfcookie']['lang'] . '-utf8.php'))
					$GLOBALS['language'] = $_COOKIE['mbfcookie']['lang'] . '-utf8';
			}

			if (isset($_REQUEST['lang'])){
				if (isset($language_conversion[substr($_REQUEST['lang'],0,2)]) && file_exists($smf_path . '/Themes/default/languages/index.' . $language_conversion[substr($_REQUEST['lang'],0,2)] . '.php'))
					$GLOBALS['language'] = $language_conversion[substr($_REQUEST['lang'],0,2)];
				else if (isset($language_conversion[substr($_REQUEST['lang'],0,2)]) && file_exists($smf_path . '/Themes/default/languages/index.' . $language_conversion[substr($_REQUEST['lang'],0,2)] . '-utf8.php'))
					$GLOBALS['language'] = $language_conversion[substr($_REQUEST['lang'],0,2)] . '-utf8';					
				else if (file_exists($smf_path . '/Themes/default/languages/index.' . $_REQUEST['lang'] . '.php'))
					$GLOBALS['language'] = $_REQUEST['lang'];					
				else if (file_exists($smf_path . '/Themes/default/languages/index.' . $_REQUEST['lang'] . '-utf8.php'))
					$GLOBALS['language'] = $_REQUEST['lang'] . '-utf8';
			}

		} else if ($synch_lang == 'true')
			$GLOBALS['language'] = $mosConfig_lang;
	}	
	$smf_lang = $GLOBALS['language'];
}
}	

if (!defined('SMF'))
{	

require_once("/SSI.php");
$_SESSION['login_url'] = '#';
$_SESSION['logout_url'] = '#';

}	

global $boarddir, $context, $txt, $scripturl, $boardurl, $settings, $mosConfig_dbprefix, $db_prefix, $db_name, $smf_date, $mosConfig_db, $mosConfig_sef, $smf_lang, $language;

include_once ( $boarddir . '/Themes/default/languages/index.' . (isset($smf_lang) ? $smf_lang : $language) . '.php');
mysql_select_db($mosConfig_db);

$result = mysql_query("
SELECT id 
FROM {$mosConfig_dbprefix}menu 
WHERE link = 'index.php?option=com_smf'");

if ($result !== false)
list($menu_item['id']) = mysql_fetch_row($result);
else
$menu_item['id'] = 1;

$myurl = basename($_SERVER['PHP_SELF']) . '?option=com_smf&Itemid=' . $menu_item['id'] . '&';

if ($mosConfig_sef == '1'){
$scripturl = $myurl;
} else {
$scripturl = $mosConfig_live_site . '/' . $myurl;
}

$smf_align = $params->get('smf_align');
$smf_personal_welcome = $params->get('smf_personal_welcome');
$smf_notification = $params->get('smf_notification');
$smf_unread = $params->get('smf_unread');
$smf_new_answers = $params->get('smf_new_answers');
$smf_new_pms = $params->get('smf_new_pms');
$smf_loggedin_time = $params->get('smf_loggedin_time');
$smf_notify_logged_in = $params->get('smf_notify_logged_in');
$smf_logout_button = $params->get('smf_logout_button');
$smf_logout_button_image = $params->get('smf_logout_button_image');

mysql_select_db($db_name);
echo '
<div align="right"><table border="0" cellpadding="0" cellspacing="0" ><tr><td><img src="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/t111.gif"></td><td background="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/t222.jpg"></td><td><img src="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/t333.gif"></td></tr><tr><td background="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/l222.jpg"></td><td><table border="0" cellpadding="0" cellspacing="0" bgcolor="#333333"><tr>
';
// If the user is logged in, display stuff like their name, new messages, etc.
if (!empty($context['user']['avatar']))
	echo '<td valign="middle">', $context['user']['avatar']['image'], '</td>';

if ($context['user']['is_logged'])
{ echo '<td colspan="2" class="logintime3" width="350"><div align="right">
	';
	{
		echo  $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';
        }
    // If defined in parameters mod_smf a special message for logged in users will displayed.
	if ($smf_personal_welcome && $smf_notify_logged_in)
		echo '<br />';

	if ($smf_notify_logged_in) 
		echo $smf_notify_logged_in;

	// Only tell them about their messages if they can read their messages!
	if ($context['allow_pm'])
		echo ', ', $txt[152], ' <a href="', $scripturl, '?action=pm">', $context['user']['messages'], ' ', $context['user']['messages'] != 1 ? $txt[153] : $txt[471], '</a>', $txt['newmessages4'], ' ', $context['user']['unread_messages'], ' ', $context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1'];
	echo '.<br />';

			// Is the forum in maintenance mode?
	if ($context['in_maintenance'] && $context['user']['is_admin'])
		echo '
						<b>', $txt[616], '</b><br />';

	// Are there any members waiting for approval?
	if (!empty($context['unapproved_members']))
		echo '
						', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'], '<br />';

	// Show the total time logged in?
	if (!empty($context['user']['total_time_logged_in']))
	{
		echo '
						', $txt['totalTimeLogged1'];

		// If days is just zero, don't bother to show it.
		if ($context['user']['total_time_logged_in']['days'] > 0)
			echo $context['user']['total_time_logged_in']['days'] . $txt['totalTimeLogged2'];

		// Same with hours - only show it if it's above zero.
		if ($context['user']['total_time_logged_in']['hours'] > 0)
			echo $context['user']['total_time_logged_in']['hours'] . $txt['totalTimeLogged3'];

		// But, let's always show minutes - Time wasted here: 0 minutes .
		echo $context['user']['total_time_logged_in']['minutes'], $txt['totalTimeLogged4'], '<br />';
	}

	echo '
						<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a><br />
						<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />
						', $context['current_time'], '<br><br><a href="', sefReltoAbs($scripturl . 'action=logout&returnurl='.$params->get('logout').'&sesc='. $context['session_id']), '">', $smf_logout_button ? '<img src="' . (!empty($smf_logout_button_image) && $smf_logout_button_image!="" ? $smf_logout_button_image : $settings['images_url'] . '/' . $context['user']['language'] . '/logout.gif').'" alt="' . $txt[108] . '" style="margin: 2px 0;" border="0" />' : $txt[108], '</a></td></tr>';


}



// Otherwise they're a guest - so politely ask them to register or login.
else
{
	$txt['welcome_guest'] = str_replace($boardurl.'/index.php?', $scripturl , $txt['welcome_guest']);
	$txt['welcome_guest'] = str_replace($scripturl.'?', $scripturl, $txt['welcome_guest']);
	$txt['welcome_guest'] = str_replace($scripturl.'action=login', sefReltoAbs($scripturl.'action=login'), $txt['welcome_guest']);

switch ($bridge_reg){
	case "bridge":
		$txt['welcome_guest'] = str_replace($scripturl.'action=register', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=register'), $txt['welcome_guest']);
		$txt['welcome_guest'] = str_replace($scripturl.'action=activate', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostCode'), $txt['welcome_guest']);
	break;

	case "SMF":
		$txt['welcome_guest'] = str_replace($scripturl.'action=register', sefReltoAbs($scripturl.'action=register'),$txt['welcome_guest']); 
		$txt['welcome_guest'] = str_replace($scripturl.'action=activate', sefReltoAbs($scripturl.'action=activate'),$txt['welcome_guest']); 
	break;

	case "default":
		$txt['welcome_guest'] = str_replace($scripturl.'action=register', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_registration&task=register'), $txt['welcome_guest']);
		$txt['welcome_guest'] = str_replace($scripturl.'action=activate', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostCode'), $txt['welcome_guest']);
	break;

	case "CB":
		$txt['welcome_guest'] = str_replace($scripturl.'action=register', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_comprofiler&task=registers'), $txt['welcome_guest']);
		$txt['welcome_guest'] = str_replace($scripturl.'action=activate', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostCode'), $txt['welcome_guest']);
	break;

	case "jw":
		$txt['welcome_guest'] = str_replace($scripturl.'action=register', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_jw_registration&task=register'), $txt['welcome_guest']);
		$txt['welcome_guest'] = str_replace($scripturl.'action=activate', sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?option=com_smf_registration&task=lostCode'), $txt['welcome_guest']);
	break;		
}
	$txt[34] = str_replace('&?','&', $txt[34]);
	if (!isset($login))
		{$login = '';}
	if (!isset($message_login))
		{$message_login = '';}

	echo '<td colspan="2" class="logintime" width="172"><div align="right">

	', $context['current_time'], '

		<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/sha1.js"></script>
</div>
		</td></tr><tr><td class="logintime"><form action="', sefReltoAbs($scripturl . 'action=login2'), '" method="post" style="margin: 3px 1ex 1px 0;"', empty($context['disable_login_hashing']) ? ' onsubmit="hashLoginPassword(this, \'' . $context['session_id'] . '\');"' : '', '>
			',$txt[35],': </td><td class="loginform"><input type="text" name="user" size="17" class="loginbutton"/></td></tr><tr><td class="logintime">
			',$txt[36],': </td><td class="loginform"><input type="password" name="passwrd" size="17" class="loginbutton"/></td></tr><tr><td colspan="2" class="logintime"><div align="right"><a href="', ($bridge_reg!='SMF' ? sefReltoAbs(basename($_SERVER['PHP_SELF']). '?option=com_smf_registration&task=lostPassword') : sefReltoAbs($scripturl . 'action=reminder')) , '">Lost Password?</a>

			<input type="submit" class="loginbutton" value="', $txt[34], '" />
			<input type="hidden" name="hash_passwrd" value="" />
			<input type="hidden" name="op2" value="login" />
			<input type="hidden" name="option" value="com_smf" />
			<input type="hidden" name="Itemid" value="', $menu_item['id'], '" />
			<input type="hidden" name="action" value="login2" />
			<input type="hidden" name="returnurl" value="', $params->get('login'), '" />
			<input type="hidden" name="lang" value="', $mosConfig_lang, '" />
			<input type="hidden" name="return" value="', $mosConfig_sef=='1' ? sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING']) : $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING'], '" />
			<input type="hidden" name="message" value="', $message_login, '" />

		</form></div></td></tr><tr><td colspan="2" class="logintime2"><div align="right">No account yet? <a href="http://whitesmokefilms.com/php_home/index.php?option=com_smf_registration&task=register">Register</a></div></td>' ;
}
if ($params->get('login') == '2' && (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'login') && (!isset($_REQUEST['option']) || $_REQUEST['option'] != 'com_smf_registration'))
	$_SESSION['return'] = $mosConfig_sef=='1' ? sefReltoAbs(basename($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING']) : $mosConfig_live_site . '/' . basename($_SERVER['PHP_SELF']) . '?' . $_SERVER['QUERY_STRING'];

echo '
	</tr></table></td><td background="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/r222.jpg"></td></tr><tr><td><img src="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/b111.gif"></td><td background="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/b222.jpg"></td><td><img src="http://whitesmokefilms.com/php_home/templates/whitesmokefilms/images/b333.gif"></td></tr><table></table>
</div>';

mysql_select_db($mosConfig_db);

?>

Link to comment
Share on other sites

Chances are, the script uses header(location: ), but I haven't looked through SMF.  If it does use the header method then a full url is required (assuming SMF doesn't replace # with the full url).  Try just making it http://google.com and see if it works.  If it does, just set the session value on the login page or what ever, and make it something like

 

$_SESSION['logout_url'] = $_SERVER['REQUEST_URI'];

 

I think URI is the one with the get variables still attached... Don't remember and don't feel like lookin in the manual lol...

Link to comment
Share on other sites

At first read through I see nothing wrong with the code.

 

Did you try "http://www.yoursite.com/page.php"?  Or did you do "page.php"?  Try the full URL ... that's what I had to use to make it work correctly.  Otherwise, this one is over my head.  Personally, I'd register and head over to the SMF Community forums if putting the full URL doesn't fix it.

 

http://www.simplemachines.org/

Link to comment
Share on other sites

The only other thing I can think of to try is to put the following code before ANYTHING else on the page:

 

<?php
  require_once('/SSI.php');
  $_SESSION['login_url'] = 'http://www.yoursite.com/loginpage.php';
  $_SESSION['logout_url'] = 'http://www.yoursite.com/logoutpage.php';
?>

 

Then do all your if's, switches, databases, queries, etc.  And I would put that at the top of the page with no if statement wrapping it -- doesn't matter whether SMF is defined ... just change the URL.

 

That's the only other thing I can think ... plug that in BEFORE ANYTHING else and see what happens.  It shouldn't matter for any function below that either because you're already called the SSI.php file, and then all you do is set session variables (which don't affect anything else you've done ...).

Link to comment
Share on other sites

If placing that code before everything else didn't do it, I have no idea.  Only other thing I can think of is that the login process you are following is not the same as what SMF says to use ... which is calling the ssi_login() function.  Using that, the $_SESSION variables will redirect as they should -- I know, I've done it.

 

I'd say keep hounding the SMF forums and see what people say.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.