作者mitsui0309 (比琪老師粉嫩嫩唷~~)
看板PHP
標題Re: [請益] PHP驗證帳號的方式
時間Wed Jun 1 02:16:07 2016
※ 引述《HwangTW (谷歌翻譯王)》之銘言:
: 因公司接觸到aspx,而我也發現這東西只要有最高權限的GUID(固定)
: 即使在無痕模式下也能直接登入
: PHP有沒有辦法可以防範這種GUID攻擊方法(我想寫的,與公司aspx無關)
: 例如在我的網站下以 index.php 為登入頁面 (以 www.example.com 為例)
: 網站之下的分支都得登入後才能觀看/操作的
: 即使直接輸入 www.example.com/test/test.php
: 1. 未經授權存取
: 直接轉到 www.example.com 待使用者輸入帳號後
: 在某個 iframe 顯示 www.example.com/test/test.php 的內容
: 2. 有授權存取
: 直接轉到 www.example.com 並在某個 iframe 顯示該內容
: 最後一個問題 cookie 該怎麼寫QQ
: 在此請教了
這是我A網頁帶POST過來的驗證程式
<?php
$id=$_POST['id'];
$email=$_POST['email'];
$checkcode=$_POST['checkcode'];
if(strtolower($checkcode)!=strtolower($_SESSION['reg_num_check']))
{
echo '<meta http-equiv="content-type" content="text/html;
charset=utf-8"><script>alert("Validate Code Error");history.go(-1);</script>';
exit;
}
if($id!=''&&$email!=''){
$sql="SELECT id FROM `".$_SiteGLOBAL['dbtable']."`.`register` WHERE
id='".$id."' AND email='".$email."'";
$result=mysql_query($sql);
list($id)=mysql_fetch_row($result);
if(empty($id)){//查無資料
echo '<meta http-equiv="content-type" content="text/html;
charset=utf-8"><script>alert("ID or E-mail Error");history.go(-1);</script>';
exit;
}else{
$_SESSION['login_reg']=$id;//紀錄session
header('location:../user.php');//到下一頁
exit;
}
}else{
echo '<meta http-equiv="content-type" content="text/html;
charset=utf-8"><script>alert("ID or E-mail Error");history.go(-1);</script>';
exit;
}
?>
你先看懂GALINE大大在講什麼,在回頭看我這段程式碼
至於我這一段,簡單的講就是
叫使用者輸入ID跟Email然後丟到資料庫去查詢
有查到就
$_SESSION['login_reg']=$id;//把查到的ID紀錄成session
header('location:../user.php');//到下一頁
exit;
沒查到就
跳出錯誤訊息"ID or E-mail Error"
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.214.194
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1464718574.A.370.html
→ tkdmaf: sql injection?????? 06/01 09:43
→ MOONRAKER: injection. 06/01 11:43
→ MOONRAKER: 用了 " 何必再用 . 06/01 11:44
感謝提醒,這是我四年前剛學PHP的程式,難免會有許多不周的地方
因為這次主要是講session,所以就沒想那麼多,就直接貼上來了
※ 編輯: mitsui0309 (1.160.214.194), 06/01/2016 23:55:53
→ MOONRAKER: Totally out-of-date X( 06/02 09:36
→ marcoyan: 不太懂為什麼用了"不能用. ?這有關係嗎@@ 06/06 11:09
推 vu0ru043: 是不是Sql那段 直接用雙引號把字串跟變數括入就好 06/06 11:35
→ vu0ru043: 因為雙引號內的變數會輸出變數的值 06/06 11:36