阿里云网站建设 部署与发布考试,网站备案取消前置审批,模版建网站,怎么样做公司网站先创建一个新闻需要的库 这样id值可以逐级递增 然后随便写个值#xff0c;让他输出一下看看 模板引入
但是这样不够美观#xff0c;这就涉及到了引入html模板
模板引入是html有一个的地方值可以通过php代码去传入过去#xff0c;其他的html界面直接调用#xff0c;这样页…
先创建一个新闻需要的库 这样id值可以逐级递增 然后随便写个值让他输出一下看看 模板引入
但是这样不够美观这就涉及到了引入html模板
模板引入是html有一个的地方值可以通过php代码去传入过去其他的html界面直接调用这样页面美观输出查询的结果也可以显示在上面 大括号括起来的就是 这样就把php的值传递到了前端代码中显示的更美观 模板调用会造成安全问题例如标题改成 在访问新闻网站的时候就会执行php代码 成功输出了123这是因为在模板调用中用到哦leval函数标题传入到这个函数中并且执行
在调用的html模板写一个php代码 也会被执行代码 为了安全的考虑就有人开发出了第三方模板 mvc模型
这样就不安全了怎么样才能安全
下载好模板第三方插件smarty
放在网站同一个目录以上代码调用即可
同样在调用文件写入一个phpinfo代码 这就不会允许 最新版本没有但是之前版本有过安全问题
复现 ?php
include ../liuyanban/config.php;
$templatefile_get_contents(new.html);//读取文件内容$id$_GET[id] ?? 1;
$sqlselect * from new where id$id;
$resultmysqli_query($con,$sql);
while($rowmysqli_fetch_row($result)){$news_title$row[1];$news_content$row[3];$news_image$row[4];
}$templatestr_replace({news_title},$news_title,$template);
$templatestr_replace({news_content},$news_content,$template);
$templatestr_replace({news_image},$news_image,$template);//替换括号tetle替换内容为第二个值替换的对象是第三个值就上面取得文件内容
eval(?.$template);!-- news_template.html --
!DOCTYPE html
html langzh-CN
headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title新闻节目/titlestylebody {font-family: Arial, sans-serif;background-color: #f4f4f4;margin: 0;padding: 20px;}.news-container {background-color: #fff;padding: 20px;border-radius: 8px;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);max-width: 800px;margin: 0 auto;}.news-title {font-size: 24px;font-weight: bold;color: #333;margin-bottom: 10px;}.news-image {max-width: 100%;height: auto;border-radius: 8px;margin-bottom: 20px;}.news-content {font-size: 16px;color: #555;line-height: 1.6;}/style
/head
body
div classnews-containerh1 classnews-title{news_title}/h1img classnews-image src{news_image} alt新闻图片p classnews-content{news_content}/p
/div
/body
/html jian kang