我已經從HTML轉換到PHP編碼,所以當我想爲我的新聞頁面創建一個鏈接時,我使用HREF將該行的id作爲鏈接,並使該部分的標題成爲可見/點擊鏈接:確保信息後?是一個整數
echo "<a href=news.php?id=".$row{'id'};
echo ">";
echo ucwords(strtolower($row{'newstitle'}));
echo "</a>";
所以,當有人點擊標題重定向文章和地址欄變成(顯然這是一個例子): http://site.com/news.php?id=1
我如何可以驗證後的信息?是id = int(它始終是一個數字),而不是一些用戶代碼或其他可能會損壞網站的輸入?我查看了消毒/驗證代碼的方法,但我發現的所有示例都是將信息輸入表單中,然後在地址中使用,而不是簡單地確保地址有效,因此轉到此處尋求幫助。 感謝
這不會*檢查輸入是一個整數的有效表示。 –
現在它會......掩蓋duff答案的方式。 – adlawson
我已經改進了我的答案,謝謝 – arnaud576875