0

I'm working on a login system for a website in which the top right corner will change depending on whether or not the user is "signed in" (a check against a session variable). I am using the following to try and show only one these two states.

        <?php if(isset($_SESSION['id'])): ?>
            <div class="large-2 large-offset-5 columns">
                <p class="right text-pad-top">@MuffinTheFox</p>
            </div>

            <div class="large-1 columns">
                <img class="avatar" src="https://pbs.twimg.com/profile_images/429861192207982592/lxaKQ4Rp.jpeg">
            </div>
        <?php else: ?>
            <div class="large-2 large-offset-7 columns">
                <a class="right text-pad-top" href="login.php">Log in/Sign up</a>
            </div>

            <div class="large-1 columns">
                <img class="avatar" src="http://placehold.it/50x50">
            </div>
        <?php endif; ?>

The problem is, when I upload the code to my server and run it, both HTML blocks display, regardless of the PHP statements.

enter image description here

There aren't any obvious errors and according to my research into the topic, this should work. Also, I tried the way without the endif; statement as well by using brackets, and that didn't work either. At this point I'm somewhat lost as to why this is happening and any help or insight would be appreciated.

Edit: Something of note, the PHP is embedded into a HTML document with a .html extension. I was under the impression that you could just inline php into a html document without issue, but I have a feeling that this might be the cause of the issue.

7
  • Are you sure it is getting parsed as PHP? Commented Mar 11, 2014 at 1:15
  • 1
    Yeah, try echoing something out from your php and see if it works. Commented Mar 11, 2014 at 1:18
  • Well, reasonably so. The other php on that page (clicking that link) works correctly. I will try to echo something though to see if it;s something on the the page itself. Commented Mar 11, 2014 at 1:19
  • So, I just threw this line into the body of the file "<?php echo "THIS IS REALLY BIG AND ANNOYING"; ?>" and nothing. I feel I should edit something into the question about how I have the php set up. Commented Mar 11, 2014 at 1:24
  • <? ?> is SGML syntax (parent language of HTML) and is therefore perfectly valid on a web page. If you right click and view source, I imagine you will see all your PHP tags right there on the page, in plain text. Is the page suffix .php or .htm(l)? Commented Mar 11, 2014 at 1:25

1 Answer 1

2

Your file is not getting parsed as PHP because PHP is not configured to parse .html files unless you tell it to. See this question for insight into how to do that. In the meantime, change your file extension to .php and it should start working as you expect.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that fixed it. I'd rather keep the file as html, but in the meantime I can just change it to .php.

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.