1

I am very new at PHP and I don't even know if this is possible but I was wondering if it was possible to only show the comment section only if the user is logged in. I use the following the check if the user if logged in or not.

<?php  if (isset($_SESSION['name'])){
/* this displays the comment section */
<div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>
        } else {
                echo "Please login";
                }
    ?>

2 Answers 2

4

do it like this and let me know.

<?php  if (isset($_SESSION['name'])){ ?>
  <div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>
  <?php  } else {
            echo "Please login";
            }
?>
Sign up to request clarification or add additional context in comments.

Comments

1

enclose the div to echo. Everytime you want to print HTML code inside of a PHP code just print it using echo "html code here";

echo '<div class="fb-comments" data-href="https://mywebsite.com" data-width="650" data-numposts="10"></div>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.