header sent even within an if

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
linus72982
Forum Newbie
Posts: 2
Joined: Sat Jul 17, 2010 11:07 pm

header sent even within an if

Post by linus72982 »

I have an if block that checks for a certain condition and, if true, sends a header location to redirect to a different page. Problem is, no matter what I do, the header within the if block always get sent. I've even gone so far as to explicitly assign a variable $blah to true and then change the if to only redirect if it's false and it still redirects. I'm stumped, am I missing something basic about the header function?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: header sent even within an if

Post by requinix »

No, but you may be missing something important about your code.

Post it.
linus72982
Forum Newbie
Posts: 2
Joined: Sat Jul 17, 2010 11:07 pm

Re: header sent even within an if

Post by linus72982 »

Code: Select all

<?php
	require ('/home/a2027775/public_html/php/facebook.php');
	require ("/home/a2027775/public_html/php/ayam_Accounts.php");
	$accounts = new Accounts;
	$facebook = new Facebook(array(
				'appId' => 'CENSORED',
				'secret' => 'CENSORED',
				'cookie' => true,
		));
	$session = $facebook->getSession();
	$me = null;
	if ($session) {
		try {
			$uid = $facebook->getUser();
			$me = $facebook->api('/me');
			} 
		catch (FacebookApiException $e) {
			error_log($e);
			}
	}
	if ($me) {
		$logoutUrl = $facebook->getLogoutUrl();
		} 
	else {
		$loginUrl = $facebook->getLoginUrl();
		}
	if ($me) {
		session_destroy();
		session_start();
		$_SESSION['uid']=$uid;
		if (!$accounts->isMerged($uid) && ($_GET['type']="newLogged")) {
			header('Location: http://www.CENSORED.com/mergeFB.php');
			}
		elseif (!isset($_SESSION['loggedIn'])) {
				$accounts->setFBUserIn($uid);
			}
		}
?>
Post Reply