Coder Social home page Coder Social logo

drafts's People

Contributors

horseluke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

drafts's Issues

面试题 - PHP - 小吉被小明的网站代码吓得瓜子都掉了......

信息摘要

出题时间: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; ?>
/*模板代码略*/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.