PHP: Logout and redirect to set page of my choice?

Associate
Joined
29 Dec 2004
Posts
2,253
Heres the bit of PHP that logs a user out of Joomla and the integrated forums i use (PunBB), at the moment it logs the user out of everything but redirects them to the forum, but i would prefer it to redirect them to the Joomla homepage, i have tried changing the path from index.php to http://richl.com but it will just put the URL as:

http://DOMAIN/index.php?option=com_punbo&Itemid=34&task=http://richl.com

The path the logout script is: http://domain/components/com_punbo/board/
I want the person to go to: http://domain/

else if ($action == 'out')
{
if ($pun_user['is_guest'] || !isset($_GET['id']) || $_GET['id'] != $pun_user['id'])
{
redirect('index.php', "", true);
exit;
}

// logout from joomla
$mainframe->logout();

// logout from punBB
PUNlogout();

redirect('index.php', $lang_login['Logout redirect'], true);
}

How can i change the code to do this?

I also tried changing it to header:("Location: http://richl.com"); but that doesnt work either as i beleive it needs to be before the rest of the page and i cannot do that as all these scripts are nestled inside the main Joomla core...

Help!
 
Theyre useless, if im lucky someone will respond with a few weeks...you guys are on the ball, always right and always quick!

Plus - this is actually a PunBB bit of code, but it has been so heavily modified to integrate with joomla that when i post on the PunBB forum they tell me they dont know and to post on the Joomla forums...but obviously the Joomla people dont know anything about it as its just someones "add on" that they dont seem to develop anymore...i even tried emailing the developers of the PunBB mod (renamed PunLA) for some help with no luck!

The only thing i dont know what it does is "redirect"...is that a PHP standard function or is that something that would have been defined somewhere else within the PunBB config/include/function files?
 
Ahh that teaches me then. Since it sounds like it's totally modded up, zip it and gimmie a link and I'll whack out the function mods for you.
 
Thats very nice of you, ill do that now...ill include everything i believe is necessary and kiss your feet if you have any luck... :)

Bare with me...
 
Try this...

Code:
function redirectHome($message, $quick = false)
{
	global $db, $pun_config, $lang_common, $pun_user;
 
       $domain = 'www.twobeds.com';

	// If the delay is 0 seconds, we might as well skip the redirect all together
	if ($pun_config['o_redirect_delay'] == '0' || $quick)
		header('Location: http://'.$domain);

	// Load the redirect template
	$tpl_redir = trim(file_get_contents(PUN_ROOT.'include/template/redirect.tpl'));


	// START SUBST - <pun_content_direction>
	$tpl_redir = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_redir);
	// END SUBST - <pun_content_direction>


	// START SUBST - <pun_char_encoding>
	$tpl_redir = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_redir);
	// END SUBST - <pun_char_encoding>


	// START SUBST - <pun_head>
	ob_start();

?>
<meta http-equiv="refresh" content="<?php echo $pun_config['o_redirect_delay'] ?>;URL=http://$domain" />
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Redirecting'] ?></title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
<?php

	$tpl_temp = trim(ob_get_contents());
	$tpl_redir = str_replace('<pun_head>', $tpl_temp, $tpl_redir);
	ob_end_clean();
	// END SUBST - <pun_head>


	// START SUBST - <pun_redir_heading>
	$tpl_redir = str_replace('<pun_redir_heading>', $lang_common['Redirecting'], $tpl_redir);
	// END SUBST - <pun_redir_heading>


	// START SUBST - <pun_redir_text>
	$tpl_temp = $message.'<br /><br />'.'<a href="'.$destination_url.'">'.$lang_common['Click redirect'].'</a>';
	$tpl_redir = str_replace('<pun_redir_text>', $tpl_temp, $tpl_redir);
	// END SUBST - <pun_redir_text>


	// START SUBST - <pun_footer>
	ob_start();

	// End the transaction
	$db->end_transaction();

	// Display executed queries (if enabled)
	if (defined('PUN_SHOW_QUERIES'))
		display_saved_queries();

	$tpl_temp = trim(ob_get_contents());
	$tpl_redir = str_replace('<pun_footer>', $tpl_temp, $tpl_redir);
	ob_end_clean();
	// END SUBST - <pun_footer>


	// START SUBST - <pun_include "*">
	while (preg_match('#<pun_include "([^/\\\\]*?)">#', $tpl_redir, $cur_include))
	{
		if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1]))
			error('Unable to process user include &lt;pun_include "'.htmlspecialchars($cur_include[1]).'"&gt; from template redirect.tpl. There is no such file in folder /include/user/');

		ob_start();
		include PUN_ROOT.'include/user/'.$cur_include[1];
		$tpl_temp = ob_get_contents();
		$tpl_redir = str_replace($cur_include[0], $tpl_temp, $tpl_redir);
	    ob_end_clean();
	}
	// END SUBST - <pun_include "*">


	// Close the db connection (and free up any result data)
	$db->close();

	//echo $tpl_redir;
	//return;

	exit(ob_mambofix($tpl_redir));
}
Fill in $domain as necessary, stick it in login.php or functions.php and call it like this:

Code:
redirectHome($lang_login['Logout redirect'], true);
I might've missed something because it's hot and I'm tired but you should get the idea of what I'm trying to do :)
 
You are a very kind sir and a gentleman. I shall give this a try now, didnt realise i would need to change very much, but indeed goes to show why i asked the question :)

Even if this doesn't work id like you to know how much i appreciate there are still people like you around!
 
Works a treat - i take it most of that is pointless PunBB stuff and you have just modified it so it uses all of the PunBB functions (even if i have the redirect time specified to something other than 0) which is fantastic...not that im too keen on meta-refreshes so i dont think ill need that, but never mind!

Once again, appreciate all your help - now i can cool down and go to bed :)
 
Back
Top Bottom