Trouble passing object to function

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
simonslater
Forum Newbie
Posts: 3
Joined: Wed May 06, 2009 10:24 pm

Trouble passing object to function

Post by simonslater »

Hello,

I am trying to pass an object into a function. however each time I get the following error:

Fatal error: Call to a member function getSession() on a non-object in /home/content/52/5733352/html/vanstand/laboratory/db_login.php on line 65


Of course, I am not sure why.

Here is the code I wrote that is causing this error:

Code: Select all

define('ID', '***************');
define('KEY', '*********************************************');
define('SEC', '*********************************************');

// new object 

$fb=new Facebook(array(
	'appId' => ID, 
	'secret' => SEC,
	'cookie' => true, ));

function restrictedtwo($object)
{
	
	//login & logout variables
	$login = $object->getLoginUrl(
     array('req_perms' => 'email, user_likes, publish_stream, read_friendlists'));
	
			//check to see if if there is a session
	if (empty($_SESSION['user_id']))
	{
		// If no session check to see if user is logged into facebook
		if($object->getSession())
		{
		//if logged in check against database
		//facebook email variable to check against db
		$fbme = $object->api('/me');
		$fbemail = $fbme['email'];
		
		db_connect('jost', 'and', 'borax', '');//to db
		
		//query for user in db
		$query = "SELECT user_id, username FROM users WHERE ";
		$query.= "email='".$fbemail."' LIMIT 1";
		$result = mysql_query($query);
			if(!$result)
			{
			die("Cannot query: <br />".mysql_error());
			}
			if (!$result_row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
				
			$log = "You are not registered";
			loginform ($log);
				exit;
			}
		session_start();
		$_SESSION['user_id'] = $result_row['user_id'];
		$_SESSION['username'] = $result_row['username'];

		}else{
			
		$log = '<center><a href="'.$login.'"> <img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif"></a></center>';
		loginform ($log);
	exit;
	}
 }
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Trouble passing object to function

Post by John Cartwright »

Please use

Code: Select all

[/syntax ] tags when posting PHP code next time (without spaces inside tags)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Trouble passing object to function

Post by John Cartwright »

Where is the code calling restrictedtwo() function? You should make sure you are passing the correct object into this function (one that has a getSession() method)
simonslater
Forum Newbie
Posts: 3
Joined: Wed May 06, 2009 10:24 pm

Re: Trouble passing object to function

Post by simonslater »

John,

I call the the function with:

Code: Select all

restrictedtwo($fb);[/syntax ]  thank you for the help.
Post Reply