好的,我目前对于编写下面代码的最佳方式感到困惑。我很困惑如何逃避回声包括更多的PHP然后进行相同的回声。我有点理解你需要使用双和单“和”。我已经包含了查看源代码时显示在chrome中的内容的屏幕截图以及下面的代码。
我设法让这个工作在另一个页面上,但是使用相同的方法它似乎不适用于此页面。
<?php echo "You are logged in as " . $_SESSION['user_name'] . "." ?>
即使只是在示例格式中,任何关于我出错的指针或方向都会受到赞赏。
我的图片显示了输出内容 - http://i.imgur.com/4EaTxP8.png
<?php session_start(); ?>
<?php if(isset($_SESSION['user_name']) && !empty($_SESSION['user_name'])){
echo "<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>test</title>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<div>
'.include 'inc/sidebar.php'; .'
<div id='content-wrapper'>
<div class='page-content'>
'.include 'inc/headerbar.php';.'
'.include 'inc/settings.php';.'
</div><!-- End Page Content -->
</div><!-- End Content Wrapper -->
</div><!-- End Page Wrapper -->
</body>
</html>";
}
else{
echo "You aren't logged in.";
} ?>
答案 0 :(得分:0)
PHP实际上是一个模板引擎本身。这就是<?php ... ?>
标记集首先存在的原因。对于大量静态HTML,您只需退出PHP模式:
<?php session_start(); ?>
<?php if(isset($_SESSION['user_name']) && !empty($_SESSION['user_name'])){ ?>
<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
答案 1 :(得分:0)
尝试这样的事情:
<?php session_start(); ?>
<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>test</title>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<?php if(isset($_SESSION['user_name']) && !empty($_SESSION['user_name'])): ?>
<div>
<?php include 'inc/sidebar.php'; ?>
<div id='content-wrapper'>
<div class='page-content'>
<?php include 'inc/headerbar.php'; ?>
<?php include 'inc/settings.php'; ?>
</div><!-- End Page Content -->
</div><!-- End Content Wrapper -->
</div><!-- End Page Wrapper -->
<?php else: ?>
You aren't logged in.
<?php endif; ?>
</body>
</html>
这种代码让我想起了我们担心Y2K错误的日子......