horseluke / drafts Goto Github PK
View Code? Open in Web Editor NEW存放草稿代码区 (Any drafts will be push here)
License: Apache License 2.0
存放草稿代码区 (Any drafts will be push here)
License: Apache License 2.0
出题时间:2015-11-26
出题人:Horse Luke
难度:低
招聘岗位:PHP工程师(业务类,非安全岗)
小明的留言板网站在访问量过大的时候总是很缓慢,而且时不时遭受黑客入侵攻击而无法正常访问,为此他找来工程师小吉请教。小吉一看,吓得瓜子都掉了……
请具体阐述这些代码存在哪些问题,并分别给出修复思路和修复代码示例。(15分)
(如不确定php代码怎么写,可写伪代码,或至少要阐明修复思路;代码已经过简化,无需考虑为什么是面向过程写法,这只是为了节约纸张)
PHP代码:
<?php
//代码略
$catid = @$_GET['catid'];
$sql = "SELECT * FROM `tc_guestbook` WHERE catid = ". $catid;
$list = $db->fetchAll($sql);
if(empty($list)){exit("该留言列表不存在");}
foreach($list as $k => $row){
$list[$k]['user'] = $db->fetchOne("SELECT * FROM `tc_user` WHERE `uid` = '". $row['uid']. "'");
}
//代码略
require __DIR__. '/tpl/default/guestbook_list.php';
guestbook_list模板代码:
/*模板代码略*/
<?php foreach($list as $row): ?>
<div>[<?php echo $row['user']["username"]; ?>]
<?php echo strlen($row["title"]) > 50 ? substr($row["title"], 0, 50). '...' : $row["title"]; ?>
</div>
<?php endforeach; ?>
/*模板代码略*/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.