模块化web程序代码
2015-03-28 17:51
239 查看
此部分是个人学习时一些资料的整理以及代码实现。
includes文件夹下包括:
modules文件夹下包括:
index.php作为索引文件
各个文件代码如下:
index.php:
config.inc.php:
header.html
footer.html
main.inc.php
search.inc.php
includes文件夹下包括:
modules文件夹下包括:
index.php作为索引文件
各个文件代码如下:
index.php:
<span style="font-size:18px;"><?PHP #index.php require('./includes/config.inc.php'); if(isset($_GET['p'])){ $p = $_GET['p']; }elseif(isset($_POST['p'])){ $p = $_POST['p']; }else{ $p = null; } //determine what page to display: switch($p){ case 'about': $page = 'about_inc.php'; $page_title = 'About This Site'; break; case 'contact': $page = 'contact.inc.php'; $page_title = 'Contact us'; break; case 'search': $page = 'search.inc.php'; $page_title = 'Search Result'; break; default: $page = 'main.inc.php'; $page_title = 'Site Home Page'; break; } //make sure the file exits; if(!file_exists('./modules/'.$page)){ $page = "main.inc.php"; $page_title = 'Site Home Page'; } //Include the header file include('./includes/header.html'); include('./modules/'.$page); include('./includes/footer.html'); ?></span>
config.inc.php:
<span style="font-size:18px;"><?PHP #config.inc.php //Errors are emailed here $conact_email = 'veaglefly@163.com'; //whether we are working on a local server $host = substr($_SERVER['HTTP_HOST'],0,5); if(in_array($host,array('local','127.0','192.1'))){ $local = true; }else{ $local = false; } if($local){ $debug = true; define('BASE_URI','/path/to/html/folder/'); define('BASE_URL','HTTP://lcoalhost/directory/'); define('DB','path/to/mysql.inc.php'); }else{ define('BASE_URI','/path/to/live/html/folder/'); define('BASE_URL','www.***.com'); define('DB','path/to/live/mysql.inc.php'); } /**********Error Management*****************/ //Create the error handler function my_error_handler($e_number,$e_message,$e_file,$e_line,$e_vars){ global $debug,$contact_email; $message = "An error occurred in script '$e_file' on line $e_line:$e_message"; //Append $e_vars to the $message: $message .=print_r($e_vars,1); if($debug){ echo '<div class = "error">'.$message.'</div>'; debug_print_backtrace(); }else{ error_log($message,1,$conact_email); if(($e_number!=E_NOTICE)&&($e_number <2048)){ echo '<div class = "error">A system error occurred.</div>'; } } } //user_error set_error_handler('my_error_handler'); ?></span>
header.html
<?PHP #header.html //This page begins the HTML header for the site //check for a $page_title value if(!isset($page_title)) $page_title = 'Default Page Title'; ?> <!DOCTYPE HTML> <html> <head> <title><?PHP echo $page_title;?></title> <link rel="stylesheet" type="text/css" href="style/style.css" title="style" /> </head> <body> <div id="main"> <div id="header"> <div id="logo"> <div id="logo_text"> <!-- class="logo_colour", allows you to change the colour of the text --> <h1><a href="index.html">colour<span class="logo_colour">blue</span></a></h1> <h2>Simple. Contemporary. Website Template.</h2> </div> </div> <div id="menubar"> <ul id="menu"> <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on --> <li><a href="index.php">Home</a></li> <li><a href="index.php?p=about">About</a></li> <li><a href="index.php?p=this">This</a></li> <li><a href="index.php?p=that">That</a></li> <li><a href="index.php?p=contact">Contact Us</a></li> </ul> </div> </div> <div id="site_content"> <div class="sidebar"> <!-- insert your sidebar items here --> <h3>Latest News</h3> <h4>New Website Launched</h4> <h5>January 1st, 2010</h5> <p>2010 sees the redesign of our website. Take a look around and let us know what you think.<br /><a href="#">Read more</a></p> <p></p> <h4>New Website Launched</h4> <h5>January 1st, 2010</h5> <p>2010 sees the redesign of our website. Take a look around and let us know what you think.<br /><a href="#">Read more</a></p> <h3>Useful Links</h3> <ul> <li><a href="#">link 1</a></li> <li><a href="#">link 2</a></li> </ul> <h3>Search</h3> <form method="get" action="index.php" id="search_form"> <p> <input type = "hidden" name = "p" value = "search"> <input class="search" type="text" name="terms" value="Search....." /> <input name="search" type="image" style="border: 0; margin: 0 0 -9px 5px;" src="style/search.png" alt="Search" title="Search" /> </p> </form> </div> <div id="content">
footer.html
<!--footer.html--> </div> </div> <div id="content_footer"></div> <div id="footer"> Copyright © colour_blue | <a href="http://validator.w3.org/check?uri=referer">HTML5</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a href="http://www.html5webtemplates.co.uk">design from HTML5webtemplates.co.uk</a> </div> </div> </body> </html>
main.inc.php
<?PHP if(!defined('BASE_URL')){ require('.../includes/config.inc.php'); $url = BASE_URL.'index.php'; header("Localtion:$url"); exit; } ?> <!-- insert the page content here --> <h1>Welcome to the colour_blue template</h1> <p>This standards compliant, simple, fixed width website template is released as an 'open source' design (under a <a href="http://creativecommons.org/licenses/by/3.0">Creative Commons Attribution 3.0 Licence</a>), which means that you are free to download and use it for anything you want (including modifying and amending it). All I ask is that you leave the 'design from HTML5webtemplates.co.uk' link in the footer of the template, but other than that...</p> <p>This template is written entirely in <strong>HTML5</strong> and <strong>CSS</strong>, and can be validated using the links in the footer.</p> <p>You can view more free HTML5 web templates <a href="http://www.html5webtemplates.co.uk">here</a>.</p> <p>This template is a fully functional 5 page website, with an <a href="examples.html">examples</a> page that gives examples of all the styles available with this design.</p> <h2>Browser Compatibility</h2> <p>This template has been tested in the following browsers:</p> <ul> <li>Internet Explorer 8</li> <li>Internet Explorer 7</li> <li>FireFox 3.5</li> <li>Google Chrome 6</li> <li>Safari 4</li> </ul>
search.inc.php
<?PHP #search.inc.php if(!defined('BASE_URL')){ require('.../includes/config.inc.php'); $url = BASE_URL.'index.php?=search'; if(isset($_GET['terms'])){ $url .= '&terms='.urlencode($_GET['terms']); } header("Localtion:$url"); exit; } echo "<h1>Search Result</h1>"; if(isset($_GET['terms'])&&($_GET['terms']!='Search...')){ for($i = 1;$i <=10;$i++){ echo <<< EOT <h4><a href = "#">Search Result </h4> <p><This is a description</p> EOT; } }else{ echo '<p class = "error">Please use the search this site.</p>'; } ?>
相关文章推荐
- 在服务器端 Web 代码中使用线程和生成异步处理程序
- 编写高质量代码改善java程序的151个建议——[110-117]异常及Web项目中异常处理
- Web MVC开发程序代码的简写方法,强类型数据和Html helper使用方法。车老师代码
- ASP.NET程序中动态修改web.config中的设置项目(前台页面代码)
- 都说Djnago框架重,那就让哥用15行代码写个django web程序! 推荐
- C#实现通过程序自动抓取远程Web网页信息的代码
- 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- 代码模块化管理和提升web性能的知识点
- Xamarin.Form中WebView调用JS代码和JS代码调用客户端程序
- 如何让webpack模块化代码兼容到ie8
- 用几十行代码写一个可以在PC Web,PC桌面,安卓,iOS上运行的程序
- WebDataMenu做工具栏程序代码
- 前端模块化实践----使用webpack打包js代码
- C#实现通过程序自动抓取远程Web网页信息的代码
- IIS7 404 模块 IIS Web Core 通知 MapRequestHandler 处理程序 StaticFile 错误代码 0x80070002
- 小程序webview嵌入iframe网页demo,微信小程序内嵌iframe网页代码,不支持打开非业务域名,请重新配置
- 程序的模块化的一些见解6-读牛人代码之感
- 如何让webpack模块化代码兼容到ie8
- 我的第十个java程序--(其实是修改别人的web代码{springmvc+mybatis},知道了原理后其实一切都变的很简单)
- 模块化web程序