1. 由於不同server,所以PHP需要增加以下紅字部分
<?php
header("Access-Control-Allow-Origin: *");
$v = $_REQUEST;
foreach($v as $i=>$v)
{
#$temp = $temp."$i=$v,";
if ($i == "occ03") {$occ03 = $v;}
if ($i == "occ11") {$occ11 = $v;}
}
$dbconn = oci_connect("xxx","yyy",
"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=1521))(CONNECT_DATA=(SID=xxx)))",
"AL32UTF8");
$sql = "
select count(*)
from occ_file
where occ03 = substr(:occ03,1,2)
and occ11 = :occ11
order by 1
";
$stid = oci_parse($dbconn, $sql);
oci_bind_by_name($stid,":occ03",$occ03);
oci_bind_by_name($stid,":occ11",$occ11);
//echo "2";
oci_execute($stid);
while ($row = oci_fetch_row($stid)) {
echo "$row[0]";
#echo "var occ11_cnt=$row[0];";
}
oci_close($dbconn);
?>
2. 由於是asynch,所以javascript在判斷時要在 onreadystatechange 就改變原本網頁element的值,另外sleep兩秒(因為asynch,太短時間怕抓到為修改以前的值)
3. 也許使用 XmlHttpRequest 的 sync option (底下true的地方) 也可以,但我未測試
function ... (
chkOCC11();
sleep(2000);
var str = document.getElementById("occ11").value;
if (str.match("請重新輸入")) {
//alert("統一編號重複,請確認")
return false;
};
return true;
)
function chkOCC11() {
var occ03 = document.getElementById("occ03").value;
var occ11 = document.getElementById("occ11").value;
var http ;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
http = new XMLHttpRequest();
} else {// code for IE6, IE5
http = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://10.1.100.201/eip/action/SA001/chkOCC11.php";
var params = "occ03=" + occ03.substr(0,2) + "&occ11=" + occ11;
var occ11_cnt;
if ("withCredentials" in http) {
http.open('POST', url + "?" + params, true);
}
else if (typeof XDomainRequest != "undefined") {
http = new XDomainRequest();
http.open('POST', url + "?" + params, true);
}
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
occ11_cnt = http.responseText;
if (occ11_cnt > 0) {
document.getElementById("occ11").value = "請重新輸入";
alert("統一編號重複,請重新輸入");
}
}
}
http.send(null);
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
4.2017/05/02 經過測試,使用同步,不使用非同步的方式就可以檢查值的正確性
5313 function chkTC_CTR11() {
5314 var ta_occ09 = document.getElementById("ta_occ09").value;
5315 var occ11 = document.getElementById("occ11").value;
5316
5317 var http ;
5318 if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
5319 http = new XMLHttpRequest();
5320 } else {// code for IE6, IE5
5321 http = new ActiveXObject("Microsoft.XMLHTTP");
5322 }
5323
5324 var url = "http://10.1.100.201/eip/action/SA001/chkTC_CTR11.php";
5325 var params = "tc_ctr11_03=" + ta_occ09.substr(0,2) + "&tc_ctr11_01=" + occ11;
5326 var result;
5327
5328 if ("withCredentials" in http) {
5329 http.open('POST', url + "?" + params, false); //false : 同步請求 ; true 非同步請求
5330 //http.open('POST', url + "?" + params, true); //false : 同步請求 ; true 非同步請求
5331 }
5332 else if (typeof XDomainRequest != "undefined") {
5333 http = new XDomainRequest();
5334 http.open('POST', url + "?" + params, false);
5335 //http.open('POST', url + "?" + params, true);
5336 }
5337 //http.timeout = 2000;
5338
5339 http.onreadystatechange = function() {//Call a function when the state changes.
5340 if(http.readyState == 4 && http.status == 200) {
5341 //alert("http.responseText = " + http.responseText);
5342 result = http.responseText;
5343 if (result == 1) {
5344 document.getElementById("ta_occ09").value = "";
5345 alert("此為業務區舊客戶,不可新增在不同分公司的業務區域");
5346 }
5347 if (result == 2) {
5348 document.getElementById("ta_occ09").value = "";
5349 alert("此為其他分公司客服區舊客戶,不可新增在業務區,請新增在客服區");
5350 }
5351 }
5352 }
5353 http.send(null);
5354 }
This man is too old to remember everything in his brain. Right now, he needs a place to write down what he has studied.
標籤
4GL
(1)
人才發展
(10)
人物
(3)
太陽能
(4)
心理
(3)
心靈
(10)
文學
(31)
生活常識
(14)
光學
(1)
名句
(10)
即時通訊軟體
(2)
奇狐
(2)
爬蟲
(1)
音樂
(2)
產業
(5)
郭語錄
(3)
無聊
(3)
統計
(4)
新聞
(1)
經濟學
(1)
經營管理
(42)
解析度
(1)
遊戲
(5)
電學
(1)
網管
(10)
廣告
(1)
數學
(1)
機率
(1)
雜趣
(1)
證券
(4)
證券期貨
(1)
ABAP
(15)
AD
(1)
agentflow
(4)
AJAX
(1)
Android
(1)
AnyChart
(1)
Apache
(14)
BASIS
(4)
BDL
(1)
C#
(1)
Church
(1)
CIE
(1)
CO
(38)
Converter
(1)
cron
(1)
CSS
(23)
DMS
(1)
DVD
(1)
Eclipse
(1)
English
(1)
excel
(5)
Exchange
(4)
Failover
(1)
Fedora
(1)
FI
(57)
File Transfer
(1)
Firefox
(3)
FM
(2)
fourjs
(1)
Genero
(1)
gladiatus
(1)
google
(1)
Google Maps API
(2)
grep
(1)
Grub
(1)
HR
(2)
html
(23)
HTS
(8)
IE
(1)
IE 8
(1)
IIS
(1)
IMAP
(3)
Internet Explorer
(1)
java
(4)
JavaScript
(22)
jQuery
(6)
JSON
(1)
K3b
(1)
ldd
(1)
LED
(3)
Linux
(120)
Linux Mint
(4)
Load Balance
(1)
Microsoft
(2)
MIS
(2)
MM
(51)
MSSQL
(1)
MySQL
(27)
Network
(1)
NFS
(1)
Office
(1)
OpenSSL
(1)
Oracle
(131)
Outlook
(3)
PDF
(6)
Perl
(60)
PHP
(33)
PL/SQL
(1)
PL/SQL Developer
(1)
PM
(3)
Postfix
(2)
postfwd
(1)
PostgreSQL
(1)
PP
(50)
python
(5)
QM
(1)
Red Hat
(4)
Reporting Service
(28)
ruby
(11)
SAP
(234)
scp
(1)
SD
(16)
sed
(1)
Selenium
(3)
Selenium-WebDriver
(5)
shell
(5)
SQL
(4)
SQL server
(8)
sqlplus
(1)
SQuirreL SQL Client
(1)
SSH
(3)
SWOT
(3)
Symantec
(2)
T-SQL
(7)
Tera Term
(2)
tip
(1)
tiptop
(24)
Tomcat
(6)
Trouble Shooting
(1)
Tuning
(5)
Ubuntu
(37)
ufw
(1)
utf-8
(1)
VIM
(11)
Virtual Machine
(2)
VirtualBox
(1)
vnc
(3)
Web Service
(2)
wget
(1)
Windows
(19)
Windows
(1)
WM
(6)
Xvfb
(2)
youtube
(1)
yum
(2)
2016年11月9日 星期三
2016年2月16日 星期二
How to do Redirect in PHP with POST and not GET
https://www.sitepoint.com/community/t/how-to-do-redirect-in-php-with-post-and-not-get/4968
<form name='fr' action='redirect.php' method='POST'>
<input type='hidden' name='var1' value='val1'>
<input type='hidden' name='var2' value='val2'>
</form>
<script type='text/javascript'>
document.fr.submit();
</script>
<form name='fr' action='redirect.php' method='POST'>
<input type='hidden' name='var1' value='val1'>
<input type='hidden' name='var2' value='val2'>
</form>
<script type='text/javascript'>
document.fr.submit();
</script>
2016年2月15日 星期一
使用PHP,Google MAPS API 呈現客戶地理資訊 example
google_map.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<script src="http://maps.googleapis.com/maps/api/js"> </script>
<script>
//var coordinates = [[22.5805149,120.4227832,'大連化學','image3'],[22.5789818,120.3178123,'建榮冷凍食品','image2']];
var offices = {"5310" : [25.055308,121.593377, "台北分公司"],
"5320" : [24.9545639,121.2026673, "桃園分公司"],
"5330" : [24.673791, 120.887685, "竹苗分公司"],
"5340" : [24.181775, 120.617205, "台中分公司"],
"5350" : [23.041664, 120.234495, "台南分公司"],
"5360" : [22.595090, 120.359171, "高雄分公司"]
};
function initialize(locations)
{
var coordinates = locations;
var oea15 = document.getElementById("oea15");
//alert(oea15.value);
//alert(offices[oea15.value][0] + "," + offices[oea15.value][1]);
var myCenter=new google.maps.LatLng(offices[oea15.value][0],offices[oea15.value][1]);
//var myCenter=new google.maps.LatLng(22.595090, 120.359171);
var mapProp = {
center:myCenter,
zoom:13,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
map.data.loadGeoJson('./twtown2010.4.json');
//map.data.loadGeoJson('./twcounty2010.6.json');
var image1 = {url : "http://labs.google.com/ridefinder/images/mm_20_red.png", size : new google.maps.Size(32, 32)};
var image2 = {url : "http://labs.google.com/ridefinder/images/mm_20_yellow.png", size : new google.maps.Size(32, 32)};
var image3 = {url : "http://labs.google.com/ridefinder/images/mm_20_green.png", size : new google.maps.Size(32, 32)};
var marker=new google.maps.Marker({
position:myCenter,
title: offices[oea15.value][2],
});
marker.setMap(map);
var idx;
for (idx=0; idx<coordinates.length; idx++) {
//alert(coordinates[idx]["LAT"] + "," + coordinates[idx]["LNG"] + "," + coordinates[idx]["OCC18"] + "," + coordinates[idx]["IMG"]);
var str = "var marker=new google.maps.Marker({ position:new google.maps.LatLng(" + coordinates[idx]["LAT"] + "," + coordinates[idx]["LNG"] + "), title: '" + coordinates[idx]["OCC18"] + "', icon:" + coordinates[idx]["IMG"] + " }); marker.setMap(map);"
eval(str);
}
//var marker=new google.maps.Marker({
// position:new google.maps.LatLng(22.5805149,120.4227832),
// title: '大連化學工業股份有限公司',
// icon: image3
//});
//marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$("#from").datepicker("option", "dateFormat", "yy/mm/dd");
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
$("#to").datepicker("option", "dateFormat", "yy/mm/dd");
});
</script>
<script>
var Submit=function(){
var URLs="http://10.1.100.201/eip/report/google_map/getDNLatLng.php";
$.ajax({
url: URLs,
data: $('#DNLatLng').serialize(),
type:"POST",
dataType:'json',
success: function(msg){
//alert(msg);
initialize(msg)
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}
</script>
</head>
<body>
<form id="DNLatLng">
<label for="分公司">分公司</label>
<select name="oea15" id="oea15">
<option value="NA" selected="selected">===請選擇===</option>
<option value="5310">台北分公司</option>
<option value="5320">桃園分公司</option>
<option value="5330">竹苗分公司</option>
<option value="5340">台中分公司</option>
<option value="5350">台南分公司</option>
<option value="5360">高雄分公司</option>
</select>
<label for="from">送貨日期 From</label>
<input type="text" id="from" name="from">
<label for="to"> to</label>
<input type="text" id="to" name="to">
<input type=button id=btn1 value=送出 onClick="Submit()"> </input>
</form>
<div id="googleMap" style="width:800;height:900px;"></div>
</body>
</html>
getDNLatLng.php
<?php
$oea15 = $_REQUEST['oea15'];
$oea02b = $_REQUEST['from'];
$oea02e = $_REQUEST['to'];
$dbstr = "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST=tiptopdb)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = topprod)))";
$dbconn = oci_connect("echo01","echo01","$dbstr","utf8");
$sql = "
select lat,lng,occ18,case when max(交運方式) != min(交運方式) then 'image2' when max(交運方式) = '外車' then 'image1' when max(交運方式) = '其它' then 'image3' end img
from (
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo01.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and a.oeauser = zx01
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200 -- < 200L
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo02.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo03.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo3a.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo06.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
),clq_file
where oea04 = occ01
and lat is not null
group by occ18,lat,lng
";
$stid = oci_parse($dbconn, $sql);
oci_bind_by_name($stid, ":oea15", $oea15);
oci_bind_by_name($stid, ":oea02b", $oea02b);
oci_bind_by_name($stid, ":oea02e", $oea02e);
oci_execute($stid);
$rows = array();
while($row = oci_fetch_assoc($stid)) {
$rows[] = $row;
}
$locations =(json_encode($rows));
echo $locations;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<script src="http://maps.googleapis.com/maps/api/js"> </script>
<script>
//var coordinates = [[22.5805149,120.4227832,'大連化學','image3'],[22.5789818,120.3178123,'建榮冷凍食品','image2']];
var offices = {"5310" : [25.055308,121.593377, "台北分公司"],
"5320" : [24.9545639,121.2026673, "桃園分公司"],
"5330" : [24.673791, 120.887685, "竹苗分公司"],
"5340" : [24.181775, 120.617205, "台中分公司"],
"5350" : [23.041664, 120.234495, "台南分公司"],
"5360" : [22.595090, 120.359171, "高雄分公司"]
};
function initialize(locations)
{
var coordinates = locations;
var oea15 = document.getElementById("oea15");
//alert(oea15.value);
//alert(offices[oea15.value][0] + "," + offices[oea15.value][1]);
var myCenter=new google.maps.LatLng(offices[oea15.value][0],offices[oea15.value][1]);
//var myCenter=new google.maps.LatLng(22.595090, 120.359171);
var mapProp = {
center:myCenter,
zoom:13,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
map.data.loadGeoJson('./twtown2010.4.json');
//map.data.loadGeoJson('./twcounty2010.6.json');
var image1 = {url : "http://labs.google.com/ridefinder/images/mm_20_red.png", size : new google.maps.Size(32, 32)};
var image2 = {url : "http://labs.google.com/ridefinder/images/mm_20_yellow.png", size : new google.maps.Size(32, 32)};
var image3 = {url : "http://labs.google.com/ridefinder/images/mm_20_green.png", size : new google.maps.Size(32, 32)};
var marker=new google.maps.Marker({
position:myCenter,
title: offices[oea15.value][2],
});
marker.setMap(map);
var idx;
for (idx=0; idx<coordinates.length; idx++) {
//alert(coordinates[idx]["LAT"] + "," + coordinates[idx]["LNG"] + "," + coordinates[idx]["OCC18"] + "," + coordinates[idx]["IMG"]);
var str = "var marker=new google.maps.Marker({ position:new google.maps.LatLng(" + coordinates[idx]["LAT"] + "," + coordinates[idx]["LNG"] + "), title: '" + coordinates[idx]["OCC18"] + "', icon:" + coordinates[idx]["IMG"] + " }); marker.setMap(map);"
eval(str);
}
//var marker=new google.maps.Marker({
// position:new google.maps.LatLng(22.5805149,120.4227832),
// title: '大連化學工業股份有限公司',
// icon: image3
//});
//marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$("#from").datepicker("option", "dateFormat", "yy/mm/dd");
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
$("#to").datepicker("option", "dateFormat", "yy/mm/dd");
});
</script>
<script>
var Submit=function(){
var URLs="http://10.1.100.201/eip/report/google_map/getDNLatLng.php";
$.ajax({
url: URLs,
data: $('#DNLatLng').serialize(),
type:"POST",
dataType:'json',
success: function(msg){
//alert(msg);
initialize(msg)
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(thrownError);
}
});
}
</script>
</head>
<body>
<form id="DNLatLng">
<label for="分公司">分公司</label>
<select name="oea15" id="oea15">
<option value="NA" selected="selected">===請選擇===</option>
<option value="5310">台北分公司</option>
<option value="5320">桃園分公司</option>
<option value="5330">竹苗分公司</option>
<option value="5340">台中分公司</option>
<option value="5350">台南分公司</option>
<option value="5360">高雄分公司</option>
</select>
<label for="from">送貨日期 From</label>
<input type="text" id="from" name="from">
<label for="to"> to</label>
<input type="text" id="to" name="to">
<input type=button id=btn1 value=送出 onClick="Submit()"> </input>
</form>
<div id="googleMap" style="width:800;height:900px;"></div>
</body>
</html>
getDNLatLng.php
<?php
$oea15 = $_REQUEST['oea15'];
$oea02b = $_REQUEST['from'];
$oea02e = $_REQUEST['to'];
$dbstr = "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST=tiptopdb)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = topprod)))";
$dbconn = oci_connect("echo01","echo01","$dbstr","utf8");
$sql = "
select lat,lng,occ18,case when max(交運方式) != min(交運方式) then 'image2' when max(交運方式) = '外車' then 'image1' when max(交運方式) = '其它' then 'image3' end img
from (
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo01.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and a.oeauser = zx01
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200 -- < 200L
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo02.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo03.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo3a.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
union all
select substr(to_char(oea02,'yyyymm'),1,6) yyyymm,oea15,oea43,ged02,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end 交運方式,
count(*) 次數,oea04,occ18,occ11,--oeb04,replace(oeb06,',',null) oeb06,
sum(oeb14*oea24) oeb14,oeb01,
oeauser,zx02,oeb04,oeb06,oeb12
from echo06.oea_file a,ged_file b,echo01.occ_file,echo01.oeb_file,echo01.zx_file,ima_file
where oea43 = b.ged01
and oea04 = occ01
and oea01 = oeb01
and oeaconf = 'Y'
and oeb04 = ima01
and imaud03 is null --冰品
and regexp_like(oea01,'SO[123789]-')
and ta_oea04 != '3'
and oea15 = :oea15
and oea02 between to_date(:oea02b,'yyyy/mm/dd') and to_date(:oea02e,'yyyy/mm/dd')
group by substr(to_char(oea02,'yyyymm'),1,6),oea43,ged02,oea15,
case when regexp_like(ged02,'大榮|大誠|日通|超峰|黑貓') then '外車' else '其它' end,oea04,occ18,occ11,--oeb04,oeb06,
oeauser,zx02,oeb01,oeb04,oeb06,oeb12
having sum(oeb12*ta_ima003/1000) < 200
),clq_file
where oea04 = occ01
and lat is not null
group by occ18,lat,lng
";
$stid = oci_parse($dbconn, $sql);
oci_bind_by_name($stid, ":oea15", $oea15);
oci_bind_by_name($stid, ":oea02b", $oea02b);
oci_bind_by_name($stid, ":oea02e", $oea02e);
oci_execute($stid);
$rows = array();
while($row = oci_fetch_assoc($stid)) {
$rows[] = $row;
}
$locations =(json_encode($rows));
echo $locations;
?>
2015年11月15日 星期日
PHP install OCI (RHEL / CentOS / Fedora)
http://antoine.hordez.fr/2012/09/30/howto-install-oracle-oci8-on-rhel-centos-fedora/
1.
yum install php.x86_64 ()
yum php-mysql.x86_64 (不確定)
yum install php-pear
yum install php-devel
2.
pear download pecl/oci8
tar vzf oci8-x.x.x.tar
cd oci8-x.x.x/
phpize
(確認整個OS只有一個php/phpize/
我在這裡吃了大苦頭。由於有兩個版本,compile一直用到舊版本。
如果有舊版本,通常會在/usr/loca/bin裡面,可以用find / -name php...找。
但是使用yum install php... 安裝的通常在/usr/bin,而$PATH的/usr/local/bin通常又先於/usr/bin,所以一直抓到舊版)
3.
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/xxx/client64/lib/ (xxx是Oracle 版本)4.
1.
yum install php.x86_64 ()
yum php-mysql.x86_64 (不確定)
yum install php-pear
yum install php-devel
2.
pear download pecl/oci8
tar vzf oci8-x.x.x.tar
cd oci8-x.x.x/
phpize
(確認整個OS只有一個php/phpize/
ph-config/pecl/pear/peardev/的版本,我在這裡吃了大苦頭。由於有兩個版本,compile一直用到舊版本。
如果有舊版本,通常會在/usr/loca/bin裡面,可以用find / -name php...找。
但是使用yum install php... 安裝的通常在/usr/bin,而$PATH的/usr/local/bin通常又先於/usr/bin,所以一直抓到舊版)
3.
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/xxx/client64/lib/ (xxx是Oracle 版本)4.
make
make install
5.
setsebool -P httpd_execmem 1 (如果有啟動SEinux)
6.
vi /etc/php.ini
or
make install
5.
setsebool -P httpd_execmem 1 (如果有啟動SEinux)
6.
vi /etc/php.ini
[OCI8]
extension=oci8.so
extension=oci8.so
cd /etc/php.d
vim oci8.ini
extension=oci8.so
vim oci8.ini
extension=oci8.so
以下為原文
HOWTO install Oracle OCI8 on RHEL / CentOS / Fedora
How to install OCI8 (PHP extension to access Oracle Databases) on a RHEL / Fedora Linux system.
Download from http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html :
EDIT 2013/09/24 : http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
Install some prerequisite
Download the OCI8 extension
Configure the extension with your Oracle client library path (change the path …/11.2/… with your own version) :
Compil and install
Configure SELinux : allows httpd to execute programs that require memory addresses that are both executable and writeable
Add the folowing configuration at the end of php.ini
Restart Apache
That’s all folks.

Download from http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html :
EDIT 2013/09/24 : http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
- RPM Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
- RPM Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
rpm -ivh instantclient-basic-linux.XXX.rpm
rpm -ivh instantclient-sdk-linux.XXX.rpm
rpm -ivh instantclient-sdk-linux.XXX.rpm
yum install php-pear
yum install php-devel
yum install php-devel
pear download pecl/oci8
tar xvzf oci8-1.4.7.tgz
cd oci8-1.4.7/
phpize
tar xvzf oci8-1.4.7.tgz
cd oci8-1.4.7/
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib/
make
make install
make install
setsebool -P httpd_execmem 1
vi /etc/php.ini
[OCI8]
extension=oci8.so
extension=oci8.so
service httpd restart
2015年11月10日 星期二
PHPMail 寄 html
#!/usr/bin/php
<?php
$cnt = 0;
$text;
function getData() {
require "/root/php/setEnv.php";
//EIP Connect
$con = new mysqli("$hostEIP","$usernameEIP","$passwordEIP","$databaseEIP");
if ($con->connect_errno)
{
die('Could not connect: ' . $con->connect_error());
}
mysqli_set_charset($con,"utf8");
$stmt = $con->prepare("
SELECT account_lastname, vfs_directory, vfs_name,
concat( 'http://xxx.xxx.xxx.xxx/eipplus/index.php?menuaction=filemanager.uifilemanager.index&path_id=', vfs_file_id ) link
FROM hplus_vfs, hplus_accounts
WHERE vfs_directory LIKE '%共用文件區%'
AND vfs_mime_type LIKE 'application%'
AND vfs_createdby_id = account_id
AND vfs_created >= sysdate( ) - 144000
");
$stmt->bind_result($name,$dir,$file,$link);
$stmt->execute();
$GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>\n";
$GLOBALS['text'] .= " <table style=' border: 1px solid #aaa; border-collapse: collapse; '> \n";
$GLOBALS['text'] .= " <tr> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳人員 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳目錄 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 檔案名稱 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> EIP連結 </th> </tr> \n";
while($stmt->fetch())
{
$GLOBALS['text'] .= " <tr> <td style='border: 1px solid #c3c3c3;'> $name </td> <td style='border: 1px solid #c3c3c3;'> $dir </td> <td style='border: 1px solid #c3c3c3;'> $file </td> <td style='border: 1px solid #c3c3c3;'> $link </td> </tr>\n";
$GLOBALS['cnt'] += 1;
}
$GLOBALS['text'] .= " </table> \n";
#$GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>";
#while($stmt->fetch()) {
# $GLOBALS['text'] .= "上傳人員 : $name<br>上傳目錄 : $dir<br>檔案名稱 : $file<br>EIP連結 : $link<br> <br>";
# $GLOBALS['cnt'] += 1;
#}
#echo $text;
#echo $cnt;
#echo $GLOBALS['cnt'];
$stmt->close();
$con->close();
}
function sendMail() {
require_once('/root/php/PHPMailer/class.phpmailer.php');
require_once('/root/php/PHPMailer/class.smtp.php');
require "/root/php/setEnv.php";
$phpmail = new PHPMailer();
$phpmail->IsSMTP(true);
#$phpmail->IsHTML(true);
$phpmail->Host = 'xxx.xxx.xxx.xxx';
$phpmail->CharSet = "utf-8";
$phpmail->From = 'mis@xxx.xxx.xxx.xxx';
$phpmail->FromName = 'EIP 自動寄信通知';
$phpmail->Subject = 'EIP 共用文件區新增檔案通知';
$html = $GLOBALS['text'];
#echo $html;
#$phpmail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
#$phpmail->Body = "<html><table style='border: 1px solid #ccc;'></table><html>";
$phpmail->MsgHTML($html);
#$phpmail->MsgHTML("test");
#$phpmail->AddAttachment( "/tmp/MailNoPrice.csv" , '有庫存無訂價.csv' );
#$phpmail->AddAddress( $mailNoPriceList,'商品行銷' );
#$phpmail->AddAddress( $mailNoPriceListVGM,'副總' );
#$phpmail->AddAddress( $mailNoPriceListFIN1,'財務主管1' );
#$phpmail->AddAddress( $mailNoPriceListFIN2,'財務主管2' );
$phpmail->AddAddress( "xxx@xxx.xxx.xxx.xxx",'全公司' );
if(! $phpmail->Send())
{
echo "通知信件寄出失敗";
echo "Mailer Error : " . $mail->ErrorInfo;
exit;
}
echo "通知信件已寄出";
}
function main() {
getData();
if ($GLOBALS['cnt'] > 0) {
sendMail();
}
}
main();
?>
<?php
$cnt = 0;
$text;
function getData() {
require "/root/php/setEnv.php";
//EIP Connect
$con = new mysqli("$hostEIP","$usernameEIP","$passwordEIP","$databaseEIP");
if ($con->connect_errno)
{
die('Could not connect: ' . $con->connect_error());
}
mysqli_set_charset($con,"utf8");
$stmt = $con->prepare("
SELECT account_lastname, vfs_directory, vfs_name,
concat( 'http://xxx.xxx.xxx.xxx/eipplus/index.php?menuaction=filemanager.uifilemanager.index&path_id=', vfs_file_id ) link
FROM hplus_vfs, hplus_accounts
WHERE vfs_directory LIKE '%共用文件區%'
AND vfs_mime_type LIKE 'application%'
AND vfs_createdby_id = account_id
AND vfs_created >= sysdate( ) - 144000
");
$stmt->bind_result($name,$dir,$file,$link);
$stmt->execute();
$GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>\n";
$GLOBALS['text'] .= " <table style=' border: 1px solid #aaa; border-collapse: collapse; '> \n";
$GLOBALS['text'] .= " <tr> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳人員 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 上傳目錄 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> 檔案名稱 </th> <th style='border: 1px solid #c3c3c3; background-color: #efefef;'> EIP連結 </th> </tr> \n";
while($stmt->fetch())
{
$GLOBALS['text'] .= " <tr> <td style='border: 1px solid #c3c3c3;'> $name </td> <td style='border: 1px solid #c3c3c3;'> $dir </td> <td style='border: 1px solid #c3c3c3;'> $file </td> <td style='border: 1px solid #c3c3c3;'> $link </td> </tr>\n";
$GLOBALS['cnt'] += 1;
}
$GLOBALS['text'] .= " </table> \n";
#$GLOBALS['text'] = "EIP 共用文件區新增檔案通知,有需要同仁可上EIP自行下載:<br> <br>";
#while($stmt->fetch()) {
# $GLOBALS['text'] .= "上傳人員 : $name<br>上傳目錄 : $dir<br>檔案名稱 : $file<br>EIP連結 : $link<br> <br>";
# $GLOBALS['cnt'] += 1;
#}
#echo $text;
#echo $cnt;
#echo $GLOBALS['cnt'];
$stmt->close();
$con->close();
}
function sendMail() {
require_once('/root/php/PHPMailer/class.phpmailer.php');
require_once('/root/php/PHPMailer/class.smtp.php');
require "/root/php/setEnv.php";
$phpmail = new PHPMailer();
$phpmail->IsSMTP(true);
#$phpmail->IsHTML(true);
$phpmail->Host = 'xxx.xxx.xxx.xxx';
$phpmail->CharSet = "utf-8";
$phpmail->From = 'mis@xxx.xxx.xxx.xxx';
$phpmail->FromName = 'EIP 自動寄信通知';
$phpmail->Subject = 'EIP 共用文件區新增檔案通知';
$html = $GLOBALS['text'];
#echo $html;
#$phpmail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
#$phpmail->Body = "<html><table style='border: 1px solid #ccc;'></table><html>";
$phpmail->MsgHTML($html);
#$phpmail->MsgHTML("test");
#$phpmail->AddAttachment( "/tmp/MailNoPrice.csv" , '有庫存無訂價.csv' );
#$phpmail->AddAddress( $mailNoPriceList,'商品行銷' );
#$phpmail->AddAddress( $mailNoPriceListVGM,'副總' );
#$phpmail->AddAddress( $mailNoPriceListFIN1,'財務主管1' );
#$phpmail->AddAddress( $mailNoPriceListFIN2,'財務主管2' );
$phpmail->AddAddress( "xxx@xxx.xxx.xxx.xxx",'全公司' );
if(! $phpmail->Send())
{
echo "通知信件寄出失敗";
echo "Mailer Error : " . $mail->ErrorInfo;
exit;
}
echo "通知信件已寄出";
}
function main() {
getData();
if ($GLOBALS['cnt'] > 0) {
sendMail();
}
}
main();
?>
2015年11月4日 星期三
PHP date (BigInt to String) and mktime (String or Integer to BigInt) conversion
<?php
echo date('H:i:s d-M-Y', 1446778800);
echo "<br>";
echo date('H:i:s d-M-Y', 1446786000);
echo "<br>";
//時,分,秒,月,日,年
$mytimestamp = mktime(11,0,0,11,6,2015);
echo "$mytimestamp";
echo "<br>";
echo date('H:i:s d-M-Y', 1446778800+36000);
echo "<br>";
echo date('H:i:s d-M-Y', 1446786000+36000);
echo "<br>";
?>
11:00:00 06-Nov-2015
13:00:00 06-Nov-2015
1446778800
21:00:00 06-Nov-2015
23:00:00 06-Nov-2015
echo date('H:i:s d-M-Y', 1446778800);
echo "<br>";
echo date('H:i:s d-M-Y', 1446786000);
echo "<br>";
//時,分,秒,月,日,年
$mytimestamp = mktime(11,0,0,11,6,2015);
echo "$mytimestamp";
echo "<br>";
echo date('H:i:s d-M-Y', 1446778800+36000);
echo "<br>";
echo date('H:i:s d-M-Y', 1446786000+36000);
echo "<br>";
?>
11:00:00 06-Nov-2015
13:00:00 06-Nov-2015
1446778800
21:00:00 06-Nov-2015
23:00:00 06-Nov-2015
2015年7月28日 星期二
安裝 PHP/oci8/mysqli
1. OS version
[root@EIP-API-AP php-5.2.17]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
2. Apache version
[root@EIP-API-AP php-5.2.17]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Oct 16 2014 14:48:21
3. PHP version
php-5.2.17
4. 拿掉/安裝 不要service
chkconfig iptables off
chkconfig postfix off
yum install vsftpd.x86_64 (vim /etc/vsftp/vsftpd.conf --> userlist_deny=NO)
5. OS command
yum install httpd-devel
yum install gcc
yum install libxml2-devel
yum install mysql-devel
yum install autoconf
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
./configure --with-apxs2=/usr/sbin/apxs --with-mysql
make
make test
make install
cp php.ini-recommended /usr/local/lib/php.ini
6. vim httpd.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
7. vim php.ini
short_open_tag=on (這樣<% 才認得,否則只能用 <?php)
8. OS command
service httpd restart
9. install oracle instant client
rpm -U oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
rpm -U oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
10. download oci8
ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
tar zxvf oci8-2.0.8.tgz
cd oci8-2.0.8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install
11. vim /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
extension=oci8.so
12. service httpd restart
13. mysqli installation
cd ~/Downloads/php-5.2.17/ext/mysqli/
phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
vim /usr/local/lib/php.ini (extension=mysqli.so)
14. phpinfo
check if oci8 installed
[root@EIP-API-AP php-5.2.17]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
2. Apache version
[root@EIP-API-AP php-5.2.17]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Oct 16 2014 14:48:21
3. PHP version
php-5.2.17
4. 拿掉/安裝 不要service
chkconfig iptables off
chkconfig postfix off
yum install vsftpd.x86_64 (vim /etc/vsftp/vsftpd.conf --> userlist_deny=NO)
5. OS command
yum install httpd-devel
yum install gcc
yum install libxml2-devel
yum install mysql-devel
yum install autoconf
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
./configure --with-apxs2=/usr/sbin/apxs --with-mysql
make
make test
make install
cp php.ini-recommended /usr/local/lib/php.ini
6. vim httpd.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
7. vim php.ini
short_open_tag=on (這樣<% 才認得,否則只能用 <?php)
8. OS command
service httpd restart
9. install oracle instant client
rpm -U oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
rpm -U oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
10. download oci8
ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
tar zxvf oci8-2.0.8.tgz
cd oci8-2.0.8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install
11. vim /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
extension=oci8.so
12. service httpd restart
13. mysqli installation
cd ~/Downloads/php-5.2.17/ext/mysqli/
phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
vim /usr/local/lib/php.ini (extension=mysqli.so)
14. phpinfo
check if oci8 installed
如何在外部網頁redirect到內部網頁後,下載doc文件
在外網的/distributor/import_doc_download.php
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $docno);
ob_clean();
flush();
readfile('http://10.1.100.101/cgi-bin/fglccgi/topprod/topcust/help/0/aim/download_doc/' . $docno);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $docno);
ob_clean();
flush();
readfile('http://10.1.100.101/cgi-bin/fglccgi/topprod/topcust/help/0/aim/download_doc/' . $docno);
2015年4月28日 星期二
在IE傳遞get參數中文遇到亂碼
方法一
https://www.peterdavehello.org/2013/10/%E5%9C%A8ie%E5%82%B3%E9%81%9Eget%E5%8F%83%E6%95%B8%E4%B8%AD%E6%96%87%E9%81%87%E5%88%B0%E4%BA%82%E7%A2%BC/
昨天被丟了一個問題:同一隻PHP程式在Chrome/Firefox丟中文參數沒問題, 在IE就會亂碼?
code大概長這樣, 主要是把傳入的參數存入db裡面, db用的是utf-8的編碼
方法二
http://www.tdes.chc.edu.tw/works/computer/study/internet/internet-02.htm
https://www.peterdavehello.org/2013/10/%E5%9C%A8ie%E5%82%B3%E9%81%9Eget%E5%8F%83%E6%95%B8%E4%B8%AD%E6%96%87%E9%81%87%E5%88%B0%E4%BA%82%E7%A2%BC/
昨天被丟了一個問題:同一隻PHP程式在Chrome/Firefox丟中文參數沒問題, 在IE就會亂碼?
code大概長這樣, 主要是把傳入的參數存入db裡面, db用的是utf-8的編碼
<!php
$con = mysql_connect("127.0.0.1","id","pw");
mysql_select_db("test", $con);
mysql_query("set names 'utf8'");
$msg = $_GET['msg'];
$sql = "INSERT INTO `db` . `table` (`column`) VALUES ('" . $msg . "')";
mysql_query($sql,$con);
mysql_close($con);
問題其實是出在IE傳遞參數時會以ANSI來編碼(即便網頁編碼是UTF-8), 自然會出現亂碼的問題, 基於現在UTF-8是主流, 所以可以在使用傳入的參數之前使用PHP內建的mb_detect_encoding做這樣的處理:$encode = mb_detect_encoding($msg, array ("UTF-8", "BIG5", "GB2312"));
if ($encode && $encode != 'UTF-8') {
$msg = iconv ( $encode, "UTF-8", $msg );
}
{ “UTF-8″, “BIG5″, “GB2312″ } 這段可以依序換成要被識別的編碼, 在編碼可以辨識(有被列入)且不是UTF-8的情況下會用PHP內建的iconv來做轉換的動作, 就可以解決這樣的問題啦~方法二
http://www.tdes.chc.edu.tw/works/computer/study/internet/internet-02.htm
當您使用瀏覽器上網時,有時會發現無法瀏覽以中文名命名的網頁或者無法下載以中文命名的檔案,這跟使用微軟
按下上述的連結會另開新的瀏覽視窗,如果您可以看到裡面的內容,則不用進行以下設定;如果您所看到的是很抱歉!找不到這個網頁……,請您進行以下的設定操作:
如果您的作業系統是 Windows XP,預設是無法瀏覽以中文名命名的網頁及無法下載以中文命名的檔案,所以請點選上述的網址進行測試與操作。
|
|
| (1) 開啟
|
|
|
(2)
點選
進階
(3)
永遠將 URL 傳送成 UTF-8 ,不要打勾。
(4)
按下確定鈕。
|
|
|
|
|
以上的設定完畢後,將瀏覽器關閉後再重新開啟瀏覽器,應該就可以瀏覽以中文命名的網頁內容了。
|
2015年3月24日 星期二
在 Windows 7 上安裝 Apache + PHP + PostgreSQL
http://yuanfarn.blogspot.tw/2013/06/windows-7-apache-php-postgresql.html
前幾天寫了篇 "在 Debian 上安裝 Apache + PHP + PostgreSQL"。這兩天突然想到,也許有些讀者只是單純想試試 Apache 和 PostgreSQL,於是乾脆也在自己的 Windows 7 上來試試如何安裝 Apache + PHP + PostgreSQL 了。
其實,在 Windows 7 上安裝也非常簡單,其中 Apache 和 PHP 只是將下載回來的壓縮檔解開,然後修改幾個設定即可。
安裝 Apache HTTP Server
Apache 目前最新的版本為 2.4.4,不過讀者可能會發現在 Apache 的網站 http://httpd.apache.org/ 上找不到 Windows 版的安裝程式,必須在 Apache Lounge (http://www.apachelounge.com/) 下載 Windows 的版本。
下載取得 httpd-2.4.4-win32.zip 這個檔案,然後將它解壓縮到 C:\,基本上會得到 C:\Apache24 這個目錄。
安裝 PHP
從 PHP 的網站 http://php.net/ 下載取得 PHP 5.4 (5.4.16) 的 VC9 x86 Thread Safe 版本,將它解壓縮並變更目錄名稱為 C:\php。
設定 Apache HTTP Server 與 PHP
從 PHP 5.4.10 這個版本之後,基本的設定如下:
首先編輯 C:\Apache24\conf\httpd.conf 這個檔案,然後加入以下幾行:
以系統管理員的身份執行命令提示字元 (Command prompt),然後執行以下這行:
最後,將 C:\Apache24、C:\Apache24\bin 及 C:\PHP 這幾個路徑加到環境變數的 PATH 裡。
修改 PHP 的設定
在 C:\PHP 找到 php.ini-development 這個檔案,複製一份並更名為 php.ini,然後修改如下:
安裝 PostgreSQL
從 PostgreSQL 的網站 http://www.postgresql.org/ 下載 Windows 版的安裝程式。根據網頁上的說明,將從 EnterpriseDB 的網站取得 9.2.4 版的安裝程式。
雙擊下載回來的 postgresql-9.2.4-1-windows.exe 安裝,並變更目錄到 C:\。因此,安裝完成會得到 C:\PostgreSQL\9.2 這個目錄。
在安裝過程依照說明設定資料庫管理員的密碼。
Windows 版本的 PostgreSQL 安裝程式會一併安裝圖形化的管理工具 pgAdmin III,在安裝後就可以直接用它來管理 PostgreSQL 了。
前幾天寫了篇 "在 Debian 上安裝 Apache + PHP + PostgreSQL"。這兩天突然想到,也許有些讀者只是單純想試試 Apache 和 PostgreSQL,於是乾脆也在自己的 Windows 7 上來試試如何安裝 Apache + PHP + PostgreSQL 了。
其實,在 Windows 7 上安裝也非常簡單,其中 Apache 和 PHP 只是將下載回來的壓縮檔解開,然後修改幾個設定即可。
安裝 Apache HTTP Server
Apache 目前最新的版本為 2.4.4,不過讀者可能會發現在 Apache 的網站 http://httpd.apache.org/ 上找不到 Windows 版的安裝程式,必須在 Apache Lounge (http://www.apachelounge.com/) 下載 Windows 的版本。
下載取得 httpd-2.4.4-win32.zip 這個檔案,然後將它解壓縮到 C:\,基本上會得到 C:\Apache24 這個目錄。
安裝 PHP
從 PHP 的網站 http://php.net/ 下載取得 PHP 5.4 (5.4.16) 的 VC9 x86 Thread Safe 版本,將它解壓縮並變更目錄名稱為 C:\php。
設定 Apache HTTP Server 與 PHP
從 PHP 5.4.10 這個版本之後,基本的設定如下:
首先編輯 C:\Apache24\conf\httpd.conf 這個檔案,然後加入以下幾行:
LoadModule php5_module "c:/php/php5apache2_4.dll" AddHandler application/x-httpd-php .php # configure the path to php.ini PHPIniDir "C:/php"接著找到 Directory index 的設定,並加入 index.php 這項:
DirectoryIndex index.html index.php向 Windows 註冊 Apache HTTP Server
以系統管理員的身份執行命令提示字元 (Command prompt),然後執行以下這行:
C:\apache24\bin\httpd -k install接著再執行將它指定為手動啟動:
sc config Apache2.4 start= demand不過通常我會將 demand 改成 auto,讓 Apache HTTP Server 自動啟動。
最後,將 C:\Apache24、C:\Apache24\bin 及 C:\PHP 這幾個路徑加到環境變數的 PATH 裡。
修改 PHP 的設定
在 C:\PHP 找到 php.ini-development 這個檔案,複製一份並更名為 php.ini,然後修改如下:
; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" ; On windows: extension_dir = "ext" extension=php_pgsql.dll基本上,要取消 PostgreSQL 這個 DLL extension 的註解。此外,也可以再取消幾個 extension 的註解,如下:
extension=php_bz2.dll extension=php_fileinfo.dll extension=php_gd2.dll extension=php_gettext.dll extension=php_gmp.dll extension=php_mbstring.dll命令提示字元 (Command prompt),執行以下這行確認載入的模組:
php -m到這裡,基本上已經完成 Apache HTTP Server 與 PHP 的設定了,可以在 C:\Apache24\htdocs 編輯一個 info.php,填入以下內容:
<?php phpinfo(); ?>然後,用瀏覽器開啟 http://localhost/info.php 查看。
安裝 PostgreSQL
從 PostgreSQL 的網站 http://www.postgresql.org/ 下載 Windows 版的安裝程式。根據網頁上的說明,將從 EnterpriseDB 的網站取得 9.2.4 版的安裝程式。
雙擊下載回來的 postgresql-9.2.4-1-windows.exe 安裝,並變更目錄到 C:\。因此,安裝完成會得到 C:\PostgreSQL\9.2 這個目錄。
在安裝過程依照說明設定資料庫管理員的密碼。
Windows 版本的 PostgreSQL 安裝程式會一併安裝圖形化的管理工具 pgAdmin III,在安裝後就可以直接用它來管理 PostgreSQL 了。
2015年3月22日 星期日
PHP上傳檔案,透過 PHP $_FILES 陣列輕鬆上傳檔案
http://www.webtech.tw/info.php?tid=24
http://gdsecret.com/post.php?id=15
上傳檔案對 PHP 來說是個相當重要的功能,PHP 可以上傳各式各樣的檔案類型,像是文件檔 word 的
.doc、Excel 的 .xls、PowerPoint 的 .ppt、PDF、exe、影片檔案如 avi、rmvb、flv ....
圖片檔案類型等等。
上傳檔案最基本的架構有三個重點:
這個頁面是要給上傳檔案的人看的,必須包含表單(form)、上傳檔案的欄位以及一個上傳按鈕。

開啟程式碼頁面
注 意表單 form 需要加上 enctype="multipart/form-data" 代表你要上傳檔案,input type="file" 這裡是上傳檔案的欄位。PHP 一次可以上傳多個檔案,這裡介紹單一檔案上傳,順利完成單一檔案上傳後,也可以嘗試看看多檔案上傳唷!
步驟二、建立一個資料夾來裝上傳的檔案
PHP 檔案上傳後會先放到一個暫存資料夾(tmp),再用 move_uploaded_file 將檔案移動到你的網站資料夾中,所以你必須建立好一個放檔案的資料夾在網站根目錄,我們暫時將這個資料夾命名為 upload。記得權限要設為可以寫入才能夠使用唷!通常預設是可以寫入,如果你待會上傳的檔案沒辦法寫入,就必須改一下資料夾權限。
步驟三、建立處理上傳檔案的 PHP 檔案 upload.php
在寫程式碼之前需要先了解 PHP 怎麼判斷檔案的各種數據

開啟程式碼頁面
如果都沒有問題的話,接著我們開始加入「移動檔案到資料夾」的動作,此動作相當的重要,主要是將剛剛上傳到伺服器暫存資料夾的檔案正式移動到你的網站目錄底下,如此一來網友才看得到。
移動檔案請用 move_uploaded_file()
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
將此 function 加到我們的程式碼中

開啟程式碼頁面
現在你已經可以將檔案上傳並順利移動到你的資料夾中囉!但是這樣其實並不完整,我們應該再加入檔案是否存在的判斷,避免有時候一個不小心重覆上傳相同的檔案,這裡可以採用 PHP 的 file_exists() 函式來判斷。

開啟程式碼頁面
相關連結
http://gdsecret.com/post.php?id=15
php.ini設定
上傳檔案前總要做些設定吧,以下列出幾個設定供參考:- file_uploads:檔案上傳 ,設為 On (允許上傳)
- upload_max_filesize:上傳最大檔案大小,預設 2M ,建議不要太大
- max_execution_time:最大程式執行時間,預設為 30 秒
- max_input_time:接收資料時間限制,建議比 max_execution_time 大
- memory _limit:最大記憶體,必須比 upload_max_filesize 大,檔案上傳才不會出錯
- post_max_size:POST資料量限制,預設 8M,必須比 upload_max_filesize 大
上傳檔案最基本的架構有三個重點:
- 上傳頁面(HTML)
- 處理檔案(PHP)
- 儲存上傳檔案的資料夾
這個頁面是要給上傳檔案的人看的,必須包含表單(form)、上傳檔案的欄位以及一個上傳按鈕。
開啟程式碼頁面
注 意表單 form 需要加上 enctype="multipart/form-data" 代表你要上傳檔案,input type="file" 這裡是上傳檔案的欄位。PHP 一次可以上傳多個檔案,這裡介紹單一檔案上傳,順利完成單一檔案上傳後,也可以嘗試看看多檔案上傳唷!
步驟二、建立一個資料夾來裝上傳的檔案
PHP 檔案上傳後會先放到一個暫存資料夾(tmp),再用 move_uploaded_file 將檔案移動到你的網站資料夾中,所以你必須建立好一個放檔案的資料夾在網站根目錄,我們暫時將這個資料夾命名為 upload。記得權限要設為可以寫入才能夠使用唷!通常預設是可以寫入,如果你待會上傳的檔案沒辦法寫入,就必須改一下資料夾權限。
步驟三、建立處理上傳檔案的 PHP 檔案 upload.php
在寫程式碼之前需要先了解 PHP 怎麼判斷檔案的各種數據
- $_FILES["file"]["name"]:上傳檔案的原始名稱。
- $_FILES["file"]["type"]:上傳的檔案類型。
- $_FILES["file"]["size"]:上傳的檔案原始大小。
- $_FILES["file"]["tmp_name"]:上傳檔案後的暫存資料夾位置。
- $_FILES["file"]["error"]:如果檔案上傳有錯誤,可以顯示錯誤代碼。
開啟程式碼頁面
如果都沒有問題的話,接著我們開始加入「移動檔案到資料夾」的動作,此動作相當的重要,主要是將剛剛上傳到伺服器暫存資料夾的檔案正式移動到你的網站目錄底下,如此一來網友才看得到。
移動檔案請用 move_uploaded_file()
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
將此 function 加到我們的程式碼中
開啟程式碼頁面
現在你已經可以將檔案上傳並順利移動到你的資料夾中囉!但是這樣其實並不完整,我們應該再加入檔案是否存在的判斷,避免有時候一個不小心重覆上傳相同的檔案,這裡可以採用 PHP 的 file_exists() 函式來判斷。
開啟程式碼頁面
相關連結
2015年1月29日 星期四
PHP在不同頁面之間傳值的三種常見方式
http://fanli7.net/a/bianchengyuyan/PHP/20140531/510971.html
接觸PHP也有幾個月了,本文總結一下這段日子中,在編程過程裏常用的3種不同頁面傳值方法,希望可以给大家参考。有什麼意見也希望大家一起討論。
一. POST傳值
post傳值是用於html的<form>表單跳轉的方法,很方便使用。例如:
二.GET傳值
GET傳值是通過跟隨url傳遞的,在頁面跳轉時,跟着url跳轉。常用於<a>標簽的使用。例如:
三.SESSION傳值
SESSION是全局變量的一種,經常用於用戶登陆後保存用戶id之類的常用數據。一旦保存到SESSION中,其他頁面都可以通過SESSION獲取,SESSION的使用要開启session:
接觸PHP也有幾個月了,本文總結一下這段日子中,在編程過程裏常用的3種不同頁面傳值方法,希望可以给大家参考。有什麼意見也希望大家一起討論。
&
一. POST傳值
post傳值是用於html的<form>表單跳轉的方法,很方便使用。例如:
<html> <form action='' method=''> <input type='text' name='name1'> <input type='hidden' name='name2' value='value'> <input type='submit' value='提交'> </form> </html>form中的action填入的是跳轉頁面的url路徑,method填入post方法。form表單中的提交按鈕按下後,就會把form中有name的內容都傳到填入的url中,可以通過$_POST['name']獲取,例如:
<?php $a=$_POST['name1']; $b=$_POST['name2']; ?>這裏有個很方便的小技巧,在input標簽中把type選为'hidden'時,這個input標簽會隱藏起來,不在頁面顯示,但這input標簽在 form中,並且有name值和value值,同样會跟隨提交按鈕傳遞過去,這種隱藏標簽可以傳遞一些不想顯示出來的內容。
二.GET傳值
GET傳值是通過跟隨url傳遞的,在頁面跳轉時,跟着url跳轉。常用於<a>標簽的使用。例如:
<a href='delete.php?id=value'>點我跳轉</a>跳轉進入xxx.php後,就能通過$_GET['id']獲取傳遞的值。GET方法常用於URL的目的是刪除或讀取某個id的php文件。
三.SESSION傳值
SESSION是全局變量的一種,經常用於用戶登陆後保存用戶id之類的常用數據。一旦保存到SESSION中,其他頁面都可以通過SESSION獲取,SESSION的使用要開启session:
<?php //session賦值 session_start(); $_SESSION['one']=value1; $_SESSION['two']=value2; //session值的讀取: $one = $_SESSION['one']; //session值的銷毀 unset($_SESSION['one']); ?>以上三種方式是常用方式,大家可以参考使用。
2015年1月28日 星期三
請問不使用< input type="submit"> 如何傳值?
http://www.programmer-club.com.tw/ShowSameTitleN/php/9872.html
| 請問不使用<input type="submit">如何傳值? | 更改我的閱讀文章字型大小大 小 |
| 作者 :
shanesss(JJM)
[ 貼文 51 | 人氣 9379 | 評價 0 | 評價/貼文 0 | 送出評價 16 次 ] |
|
| [ 給個讚 ] [ 給個讚 ] [ 回應本文 ] [ 發表新文 ] [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ] | |
|
| 作者 :
davidsets(勇ㄚ)
[ 貼文 32 | 人氣 705 | 評價 80 | 評價/貼文 2.5 | 送出評價 2 次 ] |
|
| [ 給個讚 ] [ 給個讚 ] [ 回應本文 ] [ 發表新文 ] [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ] | |
|
| 作者 :
davidsets(勇ㄚ)
[ 貼文 32 | 人氣 705 | 評價 80 | 評價/貼文 2.5 | 送出評價 2 次 ] |
|
| [ 給個讚 ] [ 給個讚 ] [ 回應本文 ] [ 發表新文 ] [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ] | |
|
| 作者 :
shanesss(JJM)
[ 貼文 51 | 人氣 9379 | 評價 0 | 評價/貼文 0 | 送出評價 16 次 ] |
|
| [ 給個讚 ] [ 給個讚 ] [ 回應本文 ] [ 發表新文 ] [ 回上頁 ] [ 回討論區列表 ] [ 回知識入口 ] | |
| 2009/5/25 上午 10:00:47 謝謝大大指導~ |
2015年1月12日 星期一
解决PHP下载乱码问题,word doc 文件等
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $docno);
ob_clean();
flush();
readfile('http://xxx/cgi-bin/fglccgi/topprod/topcust/help/0/aim/download_doc/' . $docno);
2014年12月10日 星期三
CentOS 6.2 安裝 Apache/2.2.15 and PHP/5.2.17
1. OS version
[root@EIP-API-AP php-5.2.17]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
2. Apache version
[root@EIP-API-AP php-5.2.17]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Oct 16 2014 14:48:21
3. PHP version
php-5.2.17
4. 拿掉/安裝 不要service
chkconfig iptables off
chkconfig postfix off
yum install vsftpd.x86_64 (vim /etc/vsftp/vsftpd.conf --> userlist_deny=NO)
5. OS command
yum install httpd-devel
yum install gcc
yum install libxml2-devel
yum install mysql-devel
yum install autoconf
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
./configure --with-apxs2=/usr/sbin/apxs --with-mysql
make
make test
make install
cp php.ini-recommended /usr/local/lib/php.ini
6. vim httpd.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
7. vim php.ini
short_open_tag=on (這樣<% 才認得,否則只能用 <?php)
8. OS command
service httpd restart
9. install oracle instant client
rpm -U oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
rpm -U oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
10. download oci8
ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
tar zxvf oci8-2.0.8.tgz
cd oci8-2.0.8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install
11. vim /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
extension=oci8.so
12. service httpd restart
13. mysqli installation
cd ~/Downloads/php-5.2.17/ext/mysqli/
phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
vim /usr/local/lib/php.ini (extension=mysqli.so)
14. phpinfo
check if oci8 installed
[root@EIP-API-AP php-5.2.17]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
2. Apache version
[root@EIP-API-AP php-5.2.17]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Oct 16 2014 14:48:21
3. PHP version
php-5.2.17
4. 拿掉/安裝 不要service
chkconfig iptables off
chkconfig postfix off
yum install vsftpd.x86_64 (vim /etc/vsftp/vsftpd.conf --> userlist_deny=NO)
5. OS command
yum install httpd-devel
yum install gcc
yum install libxml2-devel
yum install mysql-devel
yum install autoconf
cp -rp /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
./configure --with-apxs2=/usr/sbin/apxs --with-mysql
make
make test
make install
cp php.ini-recommended /usr/local/lib/php.ini
6. vim httpd.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
7. vim php.ini
short_open_tag=on (這樣<% 才認得,否則只能用 <?php)
8. OS command
service httpd restart
9. install oracle instant client
rpm -U oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
rpm -U oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
10. download oci8
ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so
tar zxvf oci8-2.0.8.tgz
cd oci8-2.0.8
phpize
./configure --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client64/lib
make
make install
11. vim /usr/local/lib/php.ini
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613/"
extension=oci8.so
12. service httpd restart
13. mysqli installation
cd ~/Downloads/php-5.2.17/ext/mysqli/
phpize
./configure --prefix=/usr/local/mysqli --with-php-config=/usr/local/bin/php-config --with-mysqli=/usr/bin/mysql_config
make
make install
vim /usr/local/lib/php.ini (extension=mysqli.so)
14. phpinfo
check if oci8 installed
2014年8月10日 星期日
PHP error log
兩種寫法:
1.利用error_log
http://www.w3schools.com/php/func_error_log.asp
Complete PHP Error Reference
This funtion returns TRUE on success, or FALSE on failure.
The mail received from the code above looks like this:
Complete PHP Error Reference
2.自製 function
http://richile0819.blogspot.tw/2012/07/php-write-log-phplog.html
function write_log($str,$status,$data_array) //傳入資料夾名 想寫近的狀態 資料
{
$textname = $str.date("Ymd").".txt"; //檔名 filename
$URL = "log/".$str."/"; //路徑 Path
if(!is_dir($URL)) // 路徑中的$str 資料夾是否存在 Folder exists in the path
mkdir($URL,0700);
$URL .= $textname; //完整路徑與檔名 The full path and filename
$time = $str.$status.":".date("H:i:s"); //時間 Time
$writ_tmp = '';
foreach ($data_array as $key => $value) //將陣列資料讀出 To read array data
{
$writ_tmp .= ",".$key."=".$value;
}
$write_data = $time.$writ_tmp."\n";
$fileopen = fopen($URL, "a+");
fseek($fileopen, 0);
fwrite($fileopen,$write_data); //寫資料進去 write data
fclose($fileopen);
}
1.利用error_log
http://www.w3schools.com/php/func_error_log.asp
PHP error_log() Function
Definition and Usage
The error_log() function sends an error to the server error log, a file or a remote destination.This funtion returns TRUE on success, or FALSE on failure.
Syntax
error_log(error,type,destination,headers)
| Parameter | Description |
|---|---|
| error | Required. The error message to log |
| type | Optional. Specifies the error log type. Possible log types:
|
| destination | Optional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter |
| headers | Optional. Only used if the "type" parameter is "1". Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n). Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file. |
Example
The following example sends an e-mail with a custom error:
<?php
$test=2;
if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>
$test=2;
if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>
A custom error has been triggered
2.自製 function
http://richile0819.blogspot.tw/2012/07/php-write-log-phplog.html
function write_log($str,$status,$data_array) //傳入資料夾名 想寫近的狀態 資料
{
$textname = $str.date("Ymd").".txt"; //檔名 filename
$URL = "log/".$str."/"; //路徑 Path
if(!is_dir($URL)) // 路徑中的$str 資料夾是否存在 Folder exists in the path
mkdir($URL,0700);
$URL .= $textname; //完整路徑與檔名 The full path and filename
$time = $str.$status.":".date("H:i:s"); //時間 Time
$writ_tmp = '';
foreach ($data_array as $key => $value) //將陣列資料讀出 To read array data
{
$writ_tmp .= ",".$key."=".$value;
}
$write_data = $time.$writ_tmp."\n";
$fileopen = fopen($URL, "a+");
fseek($fileopen, 0);
fwrite($fileopen,$write_data); //寫資料進去 write data
fclose($fileopen);
}
2014年7月7日 星期一
[PHP] empty(),is_null(),isset 判斷結果列表
http://seanphpbook.blogspot.tw/2009/10/php-empty-isset-php.html
寫PHP常常會用 empty 或 isset 等函式去判斷某些變數是否存在,這類函式很類似,但實際上有些許的不同,在PHP官網上特別針對類似功能的函式,整理出一張表,讓使用者可以更清楚的知道差異在哪…
寫PHP常常會用 empty 或 isset 等函式去判斷某些變數是否存在,這類函式很類似,但實際上有些許的不同,在PHP官網上特別針對類似功能的函式,整理出一張表,讓使用者可以更清楚的知道差異在哪…
php big5跟utf-8互轉的指令
php big5跟utf-8互轉的指令
PHP 程式碼:
$str=iconv("big5","UTF-8",$str);
utf-8 轉 big5
PHP 程式碼:
$str=iconv("UTF-8","big5",$str);
PHP write/mail file
#!/usr/bin/php
<?php
$cnt = 0;
function getData() {
require "setEnv.php";
//MySQL Connect
$con = mysql_connect("$hostMySQL","$usernameMySQL","$passwordMySQL");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$databaseMySQL", $con);
mysql_query("SET NAMES 'utf8'");
$result = mysql_query("
select ima01,ima127,ima128,ima262_01,ima262_02 from mobile.IMA_FILE
where ima262_01+ima262_02 > 0
and ima127 = 0 and ima128 = 0
");
$fp = fopen('/tmp/MailNoPrice.csv', 'w');
fwrite($fp, iconv("UTF-8","big5","料號").",".iconv("UTF-8","big5","可出量")."\n");
while($row = mysql_fetch_assoc($result))
{
fwrite($fp, $row['ima01']);
fwrite($fp, ",");
fwrite($fp, $row['ima262_01'] + $row['ima262_02']);
fwrite($fp, "\n");
$GLOBALS['cnt'] += 1;
}
fclose($fp);
mysql_close($con);
}
function sendMail() {
require_once('sysmail.inc.php');
require_once('class.phpmailer.php');
$phpmail = new PHPMailer();
$phpmail->IsSMTP(true);
$phpmail->Host = $SysMail['SMTPhost'];
$phpmail->CharSet = "utf-8";
$phpmail->From = 'tyruan@echochem.com.tw';
$phpmail->FromName = 'MIS';
$phpmail->Subject = '有庫存,沒訂價 料號列表 (影響外網訂價)';
$html = "共計:" . $GLOBALS['cnt'] . "筆,請儘速修正。謝謝";
$phpmail->MsgHTML($html);
$phpmail->AddAttachment( "/tmp/MailNoPrice.csv" , 'MailNoPrice.csv' );
$phpmail->AddAddress( "tyruan@echochem.com.tw",'MIS' );
$phpmail->AddCC( "tyruan@echochem.com.tw",'MIS');
$phpmail->Send();
}
function main() {
getData();
if ($GLOBALS['cnt'] > 0) {
sendMail();
}
}
main();
?>
<?php
$cnt = 0;
function getData() {
require "setEnv.php";
//MySQL Connect
$con = mysql_connect("$hostMySQL","$usernameMySQL","$passwordMySQL");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$databaseMySQL", $con);
mysql_query("SET NAMES 'utf8'");
$result = mysql_query("
select ima01,ima127,ima128,ima262_01,ima262_02 from mobile.IMA_FILE
where ima262_01+ima262_02 > 0
and ima127 = 0 and ima128 = 0
");
$fp = fopen('/tmp/MailNoPrice.csv', 'w');
fwrite($fp, iconv("UTF-8","big5","料號").",".iconv("UTF-8","big5","可出量")."\n");
while($row = mysql_fetch_assoc($result))
{
fwrite($fp, $row['ima01']);
fwrite($fp, ",");
fwrite($fp, $row['ima262_01'] + $row['ima262_02']);
fwrite($fp, "\n");
$GLOBALS['cnt'] += 1;
}
fclose($fp);
mysql_close($con);
}
function sendMail() {
require_once('sysmail.inc.php');
require_once('class.phpmailer.php');
$phpmail = new PHPMailer();
$phpmail->IsSMTP(true);
$phpmail->Host = $SysMail['SMTPhost'];
$phpmail->CharSet = "utf-8";
$phpmail->From = 'tyruan@echochem.com.tw';
$phpmail->FromName = 'MIS';
$phpmail->Subject = '有庫存,沒訂價 料號列表 (影響外網訂價)';
$html = "共計:" . $GLOBALS['cnt'] . "筆,請儘速修正。謝謝";
$phpmail->MsgHTML($html);
$phpmail->AddAttachment( "/tmp/MailNoPrice.csv" , 'MailNoPrice.csv' );
$phpmail->AddAddress( "tyruan@echochem.com.tw",'MIS' );
$phpmail->AddCC( "tyruan@echochem.com.tw",'MIS');
$phpmail->Send();
}
function main() {
getData();
if ($GLOBALS['cnt'] > 0) {
sendMail();
}
}
main();
?>
2014年7月1日 星期二
PHP中查看错误log
http://blog.csdn.net/hopestar2/article/details/5960616
php中需要查看错误log,如何设置?
首先需要在php.ini打开开关和制定错误log路径
log_errors = On
error_log = d://phperror.log //windows下的设置
如果是在linux 下,使用lighttpd服务器,则可以使用如下方式查看log文件
tail -n 20 /usr/local/lighttpd/log/php-error.log
在php代码中如何记录log,在PHP官方文档中有个函数error_log(),使用方法如下:
若成功,返回 true,否则返回 false。
php中需要查看错误log,如何设置?
首先需要在php.ini打开开关和制定错误log路径
log_errors = On
error_log = d://phperror.log //windows下的设置
如果是在linux 下,使用lighttpd服务器,则可以使用如下方式查看log文件
tail -n 20 /usr/local/lighttpd/log/php-error.log
在php代码中如何记录log,在PHP官方文档中有个函数error_log(),使用方法如下:
定义和用法
error_log() 函数向服务器错误记录、文件或远程目标发送一个错误。若成功,返回 true,否则返回 false。
语法
error_log(error,type,destination,headers)
| 参数 | 描述 |
|---|---|
| error | 必需。要记录的错误消息。 |
| type |
可选。规定错误记录的类型。 可能的记录类型:
|
| destination | 可选。规定向何处发送错误消息。该参数的值依赖于 "type" 参数的值。 |
| headers |
可选。只在 "type" 为 1 时使用。 规定附加的头部,比如 From, Cc 以及 Bcc。由 CRLF (/r/n) 分隔。 注释:在发送电子邮件时,必须包含 From 头部。可以在 php.ini 文件中或者通过此参数设置。 |
例子
本例发送一封带有自定义错误的电子邮件:<?php
$test=2;
if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>
输出:A custom error has been triggered
PS: 在调试php代码的时候,除了使用error_log()函数,还可以使用 throw new Exception()抛出异常信息。
訂閱:
文章 (Atom)

,is_null%28%29,isset%E7%89%B9%E6%AE%8A%E5%88%A4%E6%96%B7%E7%B5%90%E6%9E%9C%E5%88%97%E8%A1%A8.jpg)