Latest

英文、中文 / 諺語、片語、成語、口語對照 (2025.08.25 更新)

做表面功夫 go through the motion 目中無人;自視甚高 have one's nose in the air 有完沒完;別再說了 give it a rest  = can in 兵來將擋,水來土掩 roll with the punches (衍伸至拳擊) = take it as it comes 時間過得好慢。 The day is dragging on. 少臭美了 be full of oneself = Get over yourself! 你真是自以為是。 You are really all about yourself. 你一定找得到的。 You can't miss it. 那還用說。 You're telling me. 物超所值 get more bang for the buck 加把勁 pull one's socks up 出洋相;大吵大鬧 make a scene 風馬牛不相及 be neither here nor there 挖東牆補西牆 rob Peter to pay Paul 我覺得事有蹊蹺。 I smell a rat.  冤冤相報何時了。 Two wrongs don't make a right. 沒魚,蝦也好。 It's not so great, but it'll have to do.  自斷後路 burn one's bridge  這是掛保證的。 You can take it to the bank.  = You can quote me on that. 白手起家 rags-to-riches 放規矩點! Behave youself. = Mind your p's and q's. 悉聽尊便。 Anything you say. = It's up to you. = As you wish. 夠了!(住嘴) Cut it out! = Stop it! 閉嘴! Hold your tongue. = Shut up! 別太挑剔了! Don't be so fussy. 別搞砸了! Don't blow it. 別老叫我做東做西! Don't boss me arou...

防止HTML和SQL攻擊...還有mysql_connect()之連結失敗

不得不說上坤哥的課,真的是大學生涯的(知識)飽食時間!!
而這次坤哥在PHP課所教的是防止有人透過輸入HTML語法來破壞架構以及SQL攻擊

回想起4,5年前有位高中同學曾經使用過,人才呀~
(我倒是現在才領悟~"~)

- - -

首先
是防止HTML語法

echo $comment;

[輸入]
<b>&gt"哈哈"</b>
<b>&gt"哈囉"</b>
[輸出]
>"哈哈" >哈囉

再來~
加上禁止HTML語法換行功能
echo nl2br(htmlentities($comment, ENT_QUOTES));

[輸入]
<b>&gt"哈哈"</b>
<b>&gt"哈囉"</b>
[輸出]
<b>&gt"哈哈"</b>
<b>&gt"哈囉"</b>

但不知道為什麼我加了可以轉換單引號和雙引號的ENT_QUOTES卻依舊沒轉換= =

- - -

要防止SQL攻擊則是先講如何攻擊:

像是在密碼框輸入' OR ' ' = '
SQL指令就會變成"SELECT * FROM `person` WHERE pw`=' ' OR ' ' = ' ' ";
因為OR必為true,所以按下登入鍵後login success~♪

防止的方法則是:
$pw  = mysql_real_escape_string($_POST["password"]);

mysql_real_escape_string()可以讓一些符號做轉換
像是:
[ ' ] 變成 [ \' ]
[ " ] 變成 [ \" ]

但是以上方法我在學校(PHP 7 以下)測試成功在家(PHP 7.0.4版)卻跑出以下訊息 ↓
Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\test.php:39 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test.php on line 39

上網得知是因為PHP 7.0.0版已經移除mysql_connect()這個方法了@@
新的則是用mysqli_connect()

同理可用在修改其他SQL的方法上
如:mysqli_real_escape_string()

不過...
全部都修改後~
我為什麼連不到資料表=口=

To be continued...

留言

這個網誌中的熱門文章

公司職務 × 英文縮寫 × 中文對照 (2024.11.30 更新)

國泰世華信用卡 異常簽帳消費

打火機處理記 (注意,有爆炸危險!) (2021.09.11 更新)