3

I have problem with my code. I have this code:

<?php include "../config.php"; ?>
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title</title>
<link rel="stylesheet" href="../style.css" type="text/css" />
</head> 
<? if (!empty($_SESSION['LoggedIn'])) { ?>
    <div class="row">
        <div class="span2">
            <p><h3>Welcome <?=$_SESSION['login']?> loggedin: <?=$_SESSION['LoggedIn']?></h3> </p>
        </div>
    </div>
    <br>
    <div class="row">
        <div class="span2">     
            <h1>Menu</h1>

        </div>
        <div class="span5">   
            <h2>Header1:</h2>
        </div>
    </div>

  <?
    } else {
  ?>  
          <h1>Error</h1>
  <?         
    }
  ?>
</div>
</body>
</html> 

The result is:

Welcome admin loggedin: 1

Menu
Header1:
Error

Why error???

Where I have mistake? I think that all bracket is good. Maybe it can be problem with my localhost??? Or I dont know. Can you give me advice?

8
  • 5
    Have a look at your source. I think you'll find that the PHP still in there. Did you set up your web server to parse PHP files? Commented Dec 6, 2013 at 10:43
  • Is the session variable set and available? Check the file extension.. is it php, html? Commented Dec 6, 2013 at 10:44
  • 1
    Post the complete source output of the browser. Is <? ... ?> being parsed? Commented Dec 6, 2013 at 10:44
  • 1
    You seem to be using short tags in your last tthree PHP blocks. <? instead of <?php. Check if PHP is configured to use short tags, or just don't use them. Commented Dec 6, 2013 at 10:45
  • 1
    I believe, PHP is actually being evaluated. Thats how values are being retrieved from $_SESSION. IMO, the problem is elsewhere; the OP hasn't put in the entire code in here. Commented Dec 6, 2013 at 10:46

2 Answers 2

8

My best guess is that you have short tags disabled. Make sure that short tags (<? instead of <?php) are enabled. Or better yet, don't use them!.

Replace all of your <? with <?php, complete tag names will ensure that PHP is parsed correctly.

<?= will still be evaluated and parsed regardless of short tags being enabled or disabled.

Look at the source of the page, and see if you can see the PHP code there, if you can, short tags are not being parsed by the server.

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

10 Comments

PHP is being parsed, the login name has been printed.
@shanethehat: Correct. I have corrected. Thanks. Silly mistake on my part :D
if short tags were not enabled she will get the error at the beggining only.i dont think short tags are problem
@RishabhRaj: Why? If the short tags are not being parsed, the if/else sequence would fail. <? !== <?=.
Yup, <?= is not a short tag, it's special template syntax.
|
0

save your page as .php extension

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.