duan0821 2014-02-02 04:00
浏览 70
已采纳

PHP显示为文本而不是应用程序

So I am new to coding PHP and am working on creating a login system. I have followed this tutorial and have done everything that he has said, but when I open any of the files it just shows the code. http://www.youtube.com/watch?v=c_hNNAdyfQk

I really need help figuring this out and would love any feedback that I can get.

Here is the code that I used for index.php

    <?php
require_once 'core/init.php';

if(Session:exists('home')) {
    echo '<p>'. Session::flash('home') . '<p>';
}

$user = new User();
if($user->isLoggedIn()) {
?>
    <p> Hello <a href="#"><?php echo escape(user->data()->username);</a>!</p>

    <ul>
        <li><a href="logout.php"> Log out</a></li>
    </ul>

<?php
} else {
    echo '<p> You need to <a href="login.php">log in</a> or <a href="register.php">register</a></p>';
}
  • 写回答

2条回答 默认 最新

  • dongyuedaochen8415 2014-02-02 09:56
    关注

    Based on your comments, it seems that PHP is running correctly and the error is in the main file or the included file.

    Try the following:

    1. Make sure your included file core/init.php has <?php opening and ?> closing tags.

    2. When using include or require, the included file must not contain white spaces or line breaks before the opening tag. Make sure that init.php does not contain any white spaces or line breaks before the opening <?php tag.

    3. You forgot to close the php tag on line 9 of the sampled code:

      change: <p> Hello <a href="#"><?php echo escape(user->data()->username);</a>!</p> to:<p> Hello <a href="#"><?php echo escape(user->data()->username);?></a>!</p>

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题