I'm trying to use the Fb PHP SDK to execute different Js document.getElementById innerHTML functions, depending on whether the user is logged in to Fb or not. For some reason the function won't work for me. I know my API connection is successful, and Javascript can be inserted here, as I can call alternative alert functions ("you are logged in" :you are not logged in") in this way. But the getElementById function won't work. I've tried moving the script to the body etc, nothing working.

Any ideas? It's probably a rookie question, but I'd love it if there was a simple solution! Here's the essential code below...

<?php if ($user_profile) { ?>
	<script>
		document.getElementById('test1').innerHTML = "<p>You ARE logged in</p>";

	</script>
	<?php } else { ?>
		<script>
			document.getElementById('test1').innerHTML = "You are NOT logged in";
		</script>
	<?php } ?>

	  </head>

	  <body>

	<div id="test1">
	</div>
Member Avatar for jmichae3

I'm trying to use the Fb PHP SDK to execute different Js document.getElementById innerHTML functions, depending on whether the user is logged in to Fb or not. For some reason the function won't work for me. I know my API connection is successful, and Javascript can be inserted here, as I can call alternative alert functions ("you are logged in" :you are not logged in") in this way. But the getElementById function won't work. I've tried moving the script to the body etc, nothing working.

Any ideas? It's probably a rookie question, but I'd love it if there was a simple solution! Here's the essential code below...

<?php if ($user_profile) { ?>
	<script>
		document.getElementById('test1').innerHTML = "<p>You ARE logged in</p>";

	</script>
	<?php } else { ?>
		<script>
			document.getElementById('test1').innerHTML = "You are NOT logged in";
		</script>
	<?php } ?>

	  </head>

	  <body>

	<div id="test1">
	</div>

not knowing the sdk, your js and PHP code looks golden. but as to whether it actually works with the fb sdk or not, that's another question.
why don't you check isset() to see if $profile is even a variable that exists?
also, I saw this page:
http://stackoverflow.com/questions/7890779/get-facebook-user-id-username-to-fetch-profile-picture-without-facebook-sdk-php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.