MySQL 新增使用者&設定權限

新增:

mysql > CREATE USER '帳號'@'連線位置' IDENTIFIED BY '密碼';

設定權限:

mysql > GRANT 權限 ON db.table TO '帳號'@'連線位置';

連線位置:

%:完全開放
localhost : 本機
8.8.8.8:IP

權限:

ALL PRIVILEGES : 全開
SELECT,INSERT,UPDATE,DELETE,CREATE : 指定權限

套用權限:

mysql > FLUSH PRIVILEGES;

常用指令:

mysql > CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'dbpassword';
mysql > GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'localhost';
mysql > FLUSH PRIVILEGES;

[PHP] Debian 安裝 Composer

先安裝 php-cli ( PHP command line )

 sudo apt install php-cli

下載 Composer 安裝檔

 php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

驗證下載檔,https://composer.github.io/pubkeys.html 中取得 驗證碼,並帶入指令中,如果回覆Installer verified代表下載檔可以正常安裝

 php -r "if (hash_file('sha384', 'composer-setup.php') === '驗證碼') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

安裝 composer

php composer-setup.php

移除安裝檔

 php -r "unlink('composer-setup.php');"

將執行檔搬移到執行檔目錄

 sudo mv composer.phar /usr/local/bin/composer

安裝完成囉

#composer -V

Composer version 2.3.5 2022-04-13 16:43:00

PHP 載入圖檔

可用於載入內部非web資料夾圖檔,或外部http圖檔

$source_img = '/home/test/test.jpg'; 
//$source_img = 'https://test.jpg';
@$im = imagecreatefromjpeg($source_img);


if(!$im){ // 載入失敗顯示錯誤圖
	$w = 200;
	$h = 200;
	$fontsize = 5; // 1,2,3,4,5 max 5
	$errorstr = 'Image error';
	$im  = imagecreatetruecolor($w, $h); 
	$bgcolor = imagecolorallocate($im, 255, 255, 0);
	$textcolor  = imagecolorallocate($im, 0, 255, 255);

	imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor); // 填滿背景
	$fw = imagefontwidth($fontsize);     // width of a character
	$fh = imagefontheight($fontsize);     // height of a character
	$l = strlen($errorstr);          // number of characters
	$tw = $l * $fw;              // text width
	$th = 1 * $fw;              // text height

	$xpos = ($w - $tw)/2;
	$ypos = ($h - $th)/2;

	imagestring($im, $fontsize, $xpos, $ypos, $errorstr , $textcolor);
}

header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);
exit;

PHP 多檔案上傳

name 設為[]陣列 ,並在後方加上 multiple

<input type="file" name="userImage[]" id="userImage" multiple>

上傳處理

foreach( $_FILES[userImage][tmp_name] AS $k => $v){
	if(is_uploaded_file($_FILES['userImage']['tmp_name'][$k])) {
		$source_file = $_FILES['userImage']['tmp_name'][$k];
		$target_file = date( "Ymd.His").'_'.$_FILES['userImage']['name'][$k];
		if(move_uploaded_file($source_file,$target_file)) {
			echo $source_file.'上傳成功';
		}
	}
}

Line 自訂分享訊息

<input id="msg_data" type="text" class="form-control " value=""  />
<button onclick="sendLine();">傳Line</button>
function sendLine(){
    var msg = $( "#chat_msg_data" ).val();
    var encoded = encodeURIComponent(msg);
    if(encoded){
        window.location.replace("https://line.me/R/share?text="+encoded );
    }else{
        alert('請輸入訊息');
    }
}

1.文字內容務必urlencode過
2.傳送網址格式可以用
https://line.me/R/share?text={text_message}

https://line.me/R/msg/text/?{text_message}

更多功能可以參考

https://developers.line.biz/en/docs/line-login/using-line-url-scheme/#available-line-url-schemes

地址連結開啟Google Map

連結 : https://www.google.com/maps/place/地址

地址建議先用 urlencode 處理過

https://www.google.com/maps/place/100%E5%8F%B0%E5%8C%97%E5%B8%82%E4%B8%AD%E6%AD%A3%E5%8D%80%E5%8C%97%E5%B9%B3%E8%A5%BF%E8%B7%AF3%E8%99%9F

另外一種用法:https://www.google.com/maps/search/?api=1&query=地址

這種用法可套用google map api 達成某些功能

https://developers.google.com/maps/documentation/urls/get-started#search-action

電話超連結

按下連結時會自動開啟撥號程式打電話

連結格式 tel:電話號碼

<a href="tel:<?=$mobile;?>"><?=$mobile;?></a>
<a href="tel:<?=$tel;?>"><?=$tel;?></a>

國際標準

+國碼-電話號碼,台灣號碼如果開頭為0要把0拿掉

$call_mobile_pos = strpos($mobile, '0');
if( $call_mobile_pos === 0) {
    $call_mobile = substr($mobile,1); 
} 
<a href="tel:+886-<?=$call_mobile;?>"><?=$mobile;?></a>

市話區碼開頭為0也要移除

if( strpos($tel, '0' ) === 0) {
     $call_tel = substr($tel,1);
}
<a href="tel:+886-<?=$call_tel;?>"><?=$tel;?></a>

Bootstrap 4.6 初始頁面

一切從此開始

<?
$title= 'Hello, world!';
?>
<!doctype html>
<html lang="zh-Hant-TW">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
	<!-- jquery ui css -->
	<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" >

    <title><?=$title?></title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <!-- no ajax <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
	<!-- UI -->
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.min.js" integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2" crossorigin="anonymous"></script>
    -->
  </body>
</html>

[PHP]phplist 電子報 安裝教學

下載phplist:請至 https://www.phplist.org/ 官網下載
下載後解壓縮,只需要裡面的list資料夾

建立資料庫並設定連線帳號:

mysql> CREATE DATABASE 'phplistdb'; // 建立資料庫
mysql> CREATE USER 'phplist'@'localhost' IDENTIFIED BY 'password'; // 建立連線使用者
mysql> GRANT ALL PRIVILEGES ON phplist.* TO 'phplist'@'localhost'; // 設定使用者權限
mysql> FLUSH PRIVILEGES; // 更新權限

config/config.php 基本設定( 更多設定資料可參考config_extended.php )

 // 語言
 $language_module = 'english.inc';
 // 資料庫位址
 $database_host = 'localhost';
 // 資料庫名稱
 $database_name = 'phplistdb';
 // 資料庫連線使用者
 $database_user = 'phplist';
 // 資料庫密碼
 $database_password = 'password';
 // 如果有更換路徑請加入此設定
 $pageroot = '/lists';

資料庫初始化設定:

至管理介面 http://URL/lists/admin/
按下 Initialise Database 連結
照說明填寫設定欄位就可以使用