Saturday, June 6, 2015
Thursday, June 4, 2015
Sunday, September 30, 2012
ป้องกัน MySql Injection
function clean_input($input) {
GLOBAL $linkID;
if(get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
#ตัด html tag
$input = strip_tags($input);
return mysql_real_escape_string($input,$linkID);
}
วิธีใช้ก็ง่ายมากครับ
ปกติเรารับค่ามาจากฟอร์ม ส่งมา เราจะเขียนคำสั่งประมาณนี้ ใช่เปล่าหละครับ
พอเราจะใช้ฟังก์ชั่น เราก็ครอบมันไว้อีกชั้นหนึ่งก็ได้ ไม่เปลืองเนื้อที่ดี
$name = clean_input($_POST["name"]);
$email = clean_input($_POST["email"]);
GLOBAL $linkID;
if(get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
#ตัด html tag
$input = strip_tags($input);
return mysql_real_escape_string($input,$linkID);
}
วิธีใช้ก็ง่ายมากครับ
ปกติเรารับค่ามาจากฟอร์ม ส่งมา เราจะเขียนคำสั่งประมาณนี้ ใช่เปล่าหละครับ
<?
$name = $_POST["name"];
$email = $_POST["email"];
?>
$name = $_POST["name"];
$email = $_POST["email"];
?>
พอเราจะใช้ฟังก์ชั่น เราก็ครอบมันไว้อีกชั้นหนึ่งก็ได้ ไม่เปลืองเนื้อที่ดี
$name = clean_input($_POST["name"]);
$email = clean_input($_POST["email"]);
สร้าง Google map
ขันแรกเลยครับ
เราต้องลง ทะเบียน API KEY กับ google ก่อน ที่ http://code.google.com/intl/th/apis/maps/signup.html
ถ้าเราใช้ localhost ก็ใส่ localhost หรือ 127.0.0.1 ก็ได้
ติ๊กที่ checkbox I have read and agree with the terms and conditions (printable version) กด Gennerate key เราจะได้ API มาชุดหนึ่ง
ผมใช้ http://localhost แล้ว generate จะได้
Code
มาใช้งานแล้ว
ต่อไป .. หาจุดพิกัดตัวเองซะก่อน เราจะได้เอาแค่ค่า Latitude , Longtitude ครับ
ผมไปหาจากเว็บนี้ http://www.gorissen.info/Pierre/maps/googleMapLocation.php
ซูม ซูม แล้วคลิ๊กดูข้างขวาจะเห็น แล้วมาลองสร้างแมปง่าย ๆ กันดูนะครับ
Code

แค่นี้ ก็ได้แมปมาแสดงอย่างสวยหรูในเว็บเราแล้ว .. เย้ !!
ส่วนรูปนี้คือ ระบบแหล่งท่องเที่ยวออนไลน์ ที่ผมทำเสร็จแล้ว
เราต้องลง ทะเบียน API KEY กับ google ก่อน ที่ http://code.google.com/intl/th/apis/maps/signup.html
ถ้าเราใช้ localhost ก็ใส่ localhost หรือ 127.0.0.1 ก็ได้
ติ๊กที่ checkbox I have read and agree with the terms and conditions (printable version) กด Gennerate key เราจะได้ API มาชุดหนึ่ง
ผมใช้ http://localhost แล้ว generate จะได้
Code
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAg38oHhN2wV_zgKsKydXuIRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ3S4_IiZWFHj-fcaSsEj07Q6YVsA" type="text/javascript"></script>
มาใช้งานแล้ว
ต่อไป .. หาจุดพิกัดตัวเองซะก่อน เราจะได้เอาแค่ค่า Latitude , Longtitude ครับ
ผมไปหาจากเว็บนี้ http://www.gorissen.info/Pierre/maps/googleMapLocation.php
ซูม ซูม แล้วคลิ๊กดูข้างขวาจะเห็น แล้วมาลองสร้างแมปง่าย ๆ กันดูนะครับ
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps ของฉัน</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAg38oHhN2wV_zgKsKydXuIRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ3S4_IiZWFHj-fcaSsEj07Q6YVsA" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var map = new GMap2(document.getElementById("map_canvas"));
//ใส่ค่าละติจูด , ลองติจูด , ระยะการซูม
map.setCenter(new GLatLng(12.182634, 99.849243), 11);
map.setUIToDefault();
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 640px; height: 480px"></div>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps ของฉัน</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAg38oHhN2wV_zgKsKydXuIRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ3S4_IiZWFHj-fcaSsEj07Q6YVsA" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var map = new GMap2(document.getElementById("map_canvas"));
//ใส่ค่าละติจูด , ลองติจูด , ระยะการซูม
map.setCenter(new GLatLng(12.182634, 99.849243), 11);
map.setUIToDefault();
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<div id="map_canvas" style="width: 640px; height: 480px"></div>
</body>
</html>
แค่นี้ ก็ได้แมปมาแสดงอย่างสวยหรูในเว็บเราแล้ว .. เย้ !!
ส่วนรูปนี้คือ ระบบแหล่งท่องเที่ยวออนไลน์ ที่ผมทำเสร็จแล้ว
Subscribe to:
Posts (Atom)