繁体   English   中英

在变量中包含php include

[英]Include php include inside a variable

一位客户要求我们在其网站上添加一个可编辑页面,他们可以通过外部cms更新该页面。 那里没有戏; 我可以用include“ filename.php”轻松地称呼它; 函数,但是我卡住的地方是此外部文件需要在登录后进行,因此,除非我将其包含在现有$ usermessage变量中,否则无论是否登录,它都会不断显示。

我必须编辑一个现有的,以前构建的站点(已有几年的历史了),所以我对当前的设置方式有些犹豫,但是有什么办法可以将文件包含在$ usermessage中吗?

请参阅下面的代码,感谢您的任何帮助...

<?php
require_once "header.php"; 
#require_once "onlinearchive.php";

if (isset($_SESSION['loginid']) && isset($_SESSION['email']))
{
    $session_email = $_SESSION['email'];
    $query = sprintf("SELECT name FROM login WHERE email = '%s' LIMIT 1",
    mysql_real_escape_string($session_email));

    $result = mysql_query($query);
    $username = '';
    $usermessage = '';
    $intevents = '';

    while ($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
        $username = $row['name'];
    }

    if ($username)
    {
        $username = 'Welcome ' . $username;
    }
    $usermessage = '<p><span class="green"><strong>'.$username.'</strong></span>
<strong> to the Member’s Area. </strong><br><br>Here you’ll be able to view 
news and notifications unique to IPA Members, so please check back regularly 
for updates.<br><br></p>';

}
else
{
    $usermessage = '<p><span class="green"><strong>To access the Member’s Area, 
please <a href="login.php">Log in</a> or <a href="login.php">register</a>
</strong></span><br>';
}

?>
<div id="page-title"><p>IPA Member’s Area</p></div>         

<div id="container" class="clearfix">


    <div id="content">
        <?php echo $usermessage; ?>


    </div> <!--end content-->

如果文件filename.php的结构如下:

filename.php的示例:

<?php
//Example of filename.php

$usermessage_to_return = "here the message to return";
return $usermessage_to_return;

将filename.php的内容导入另一个文件:

<?php
//Example to import filename.php

$usermessage = require 'filename.php';
echo $usermessage;
//here the message to return

诀窍是return filename.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM