判斷有效連結:
- 10月 14 週五 201613:58
PHP curl 判斷有效連結
判斷有效連結:
- 10月 14 週三 201520:39
sublime安裝
- 10月 14 週三 201520:21
PHP教學(二)MySQL資料庫設定

xampp解壓縮執行後, http://localhost 可以看到xampp的畫面,可以再輸入 http://localhost/phpmyadmin 進入資料庫管理網頁。
剛開始xampp資料庫沒有密碼, 請注意畫面下方紅字部份,我們要自行設定密碼, 請到上面按「權限」,點「使用候:root」〔 王機:localhost」的右邊圖形。
- 10月 14 週三 201520:09
PHP教學(一)伺服器安裝

PHP需要安裝Apache伺服器,並把php檔案存在Apache內的「www」或「htdocs」資料夾內,才可以執行。
Apache伺服器可以用xampp或Appserv安裝,xampplite為免安裝伺服器,解壓縮後,執行xampp_start,即可以使用。
- 3月 29 週四 201209:38
Synology NAS的cron排程
程式碼:存成網頁cronjobs.php
<?php
if ($_REQUEST['action'] == 'save') {
$out='';
for($r=1;$r<=$_REQUEST['rows'];++$r)
if ($_REQUEST['r'.$r.'c0']!='') for($c=0;$c<7;++$c) $out.=$_REQUEST['r'.$r.'c'.$c].($c<6?chr(9):chr(10));
file_put_contents('/etc/crontab', $out);
exec('killall crond;crond');
}
$filearray=file('/etc/crontab');
$_REQUEST['action'] == '';
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>cronjobs</title>
<style>body,input{font:12px Arial;margin-right:1px;margin-bottom:1px}h3{font-family:Arial}
body{background-color:#ddf}</style>
<script>
function mark(r) {
var e=document.getElementsByName(r+'c0')[0];
if (e.value.charAt(0)=='#')
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#444';
else
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#090';
}
</script>
</head><body><h3>CronJobs</h3>
<form method="post" action="cronjobs.php">
<input type="hidden" id="action" name="action" value="">
<?php
$r=0;
foreach($filearray as $rec) {
$r++; $c=0;$f=explode(chr(9),$rec);
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" '.($r==1?'readonly':'').' value="'.$f[0].'"/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[1].'"/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[2].'"/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[3].'"/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[4].'"/>';
print '<input name="r'.$r.'c5" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[5].'"/>';
print '<input name="r'.$r.'c6" type="text" size="40" '.($r==1?'readonly':'').' value="'.$f[6].'"/>';
if ($r>1) {
print '<script>mark("r'.$r.'")</script>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/>
<?php }
print '<br/>';
}
$rmax=2+$r++;
for($r;$r<=$rmax;$r++) {
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" value=""/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" value=""/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" value=""/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" value=""/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c5" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c6" type="text" size="40" value=""/>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/><br/>
<?php } ?>
<input type="hidden" name="rows" value="<?php print --$r ?>"/>
<input type="button" value="save /etc/crontab & restart crond" style="margin-top:6px"
onclick="document.getElementById('action').value='save';submit()"/>
</form></body></html>
<?php
if ($_REQUEST['action'] == 'save') {
$out='';
for($r=1;$r<=$_REQUEST['rows'];++$r)
if ($_REQUEST['r'.$r.'c0']!='') for($c=0;$c<7;++$c) $out.=$_REQUEST['r'.$r.'c'.$c].($c<6?chr(9):chr(10));
file_put_contents('/etc/crontab', $out);
exec('killall crond;crond');
}
$filearray=file('/etc/crontab');
$_REQUEST['action'] == '';
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>cronjobs</title>
<style>body,input{font:12px Arial;margin-right:1px;margin-bottom:1px}h3{font-family:Arial}
body{background-color:#ddf}</style>
<script>
function mark(r) {
var e=document.getElementsByName(r+'c0')[0];
if (e.value.charAt(0)=='#')
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#444';
else
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#090';
}
</script>
</head><body><h3>CronJobs</h3>
<form method="post" action="cronjobs.php">
<input type="hidden" id="action" name="action" value="">
<?php
$r=0;
foreach($filearray as $rec) {
$r++; $c=0;$f=explode(chr(9),$rec);
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" '.($r==1?'readonly':'').' value="'.$f[0].'"/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[1].'"/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[2].'"/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[3].'"/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[4].'"/>';
print '<input name="r'.$r.'c5" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[5].'"/>';
print '<input name="r'.$r.'c6" type="text" size="40" '.($r==1?'readonly':'').' value="'.$f[6].'"/>';
if ($r>1) {
print '<script>mark("r'.$r.'")</script>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/>
<?php }
print '<br/>';
}
$rmax=2+$r++;
for($r;$r<=$rmax;$r++) {
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" value=""/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" value=""/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" value=""/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" value=""/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c5" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c6" type="text" size="40" value=""/>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/><br/>
<?php } ?>
<input type="hidden" name="rows" value="<?php print --$r ?>"/>
<input type="button" value="save /etc/crontab & restart crond" style="margin-top:6px"
onclick="document.getElementById('action').value='save';submit()"/>
</form></body></html>
- 3月 28 週三 201221:50
php讀取csv的方法
php讀取csv的方法:
$dbname="import.csv"; //開啟
if ( !$fp = fopen($dbname,"r") ) { //假如開啟錯誤
echo "Cannot open $dbname\n"; //顯示錯誤
exit;
}else{ //開啟成功
$size = filesize($dbname)+1; //取得筆數
$row=0; //從0筆開始讀取
while($temp=fgetcsv($fp,$size,",")){ //讀取csv資料給temp陣列
if ($row>0){ //假如筆數大於0
$sql="INSERT INTO `a` ( `a1` , `a2` , `a5` ) VALUES ('$temp[1]','$temp[0]','$temp[15]')"; //寫入資料庫
$result=mysql_query($sql); //執行
}
$row=$row+1;
}
fclose($fp); //關閉檔案
}
$dbname="import.csv"; //開啟
if ( !$fp = fopen($dbname,"r") ) { //假如開啟錯誤
echo "Cannot open $dbname\n"; //顯示錯誤
exit;
}else{ //開啟成功
$size = filesize($dbname)+1; //取得筆數
$row=0; //從0筆開始讀取
while($temp=fgetcsv($fp,$size,",")){ //讀取csv資料給temp陣列
if ($row>0){ //假如筆數大於0
$sql="INSERT INTO `a` ( `a1` , `a2` , `a5` ) VALUES ('$temp[1]','$temp[0]','$temp[15]')"; //寫入資料庫
$result=mysql_query($sql); //執行
}
$row=$row+1;
}
fclose($fp); //關閉檔案
}
- 3月 18 週日 201221:05
php執行javaScript的語法
php執行javaScript的語法
echo "<script language=\"JavaScript\">";
echo "window.alert(\"你未登入\");"; //警告對話方塊
echo "location.href(\"./\");"; //到首頁
echo "</script>";
- 11月 03 週四 201110:07
在刪除資料庫前確認
在<head>與</head>之間放下面語法:
<script type="text/javascript">
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
- 11月 03 週四 201109:22
檢查ta1~ta20與tanser1~20是否相同,$score分數+5分
檢查ta1~ta20與tanser1~20是否相同,$score分數+5分
$score=0;
for($i=1;$i<=20;$i++){
$ta="ta" . $i;
$tb="tanser" . $i;
if( $_POST[$ta]==$_POST[$tb]){
$score += 5;
}
}

