2016年2月23日 星期二

php 網址傳值的方法




◎GET:給網址傳值用的變數呼叫法

什麼是網址傳值?
比方說今天有一篇文章,它的編號是100,
而秀出文章的那個頁面假設叫 article_show.php,
那麼我就可以直接用網址傳值:

article_show.php?aid=100

問號後面的是變數的名稱和值,
語法是:?變數=值&變數=值&變數=值
中間用&隔開。

所以說如果除了文章編號之外我想要再多加一些變數像是文章分類,
我就可以這樣用:

article_show.php?category=2&aid=100

也就是第2個分類、第100篇文章。

而要在php頁面的程式去抓取你網址傳來的值,
就是要使用$_GET,
比方此例就是$_GET['aid']
抓到的值就是100。
(也就是 echo $_GET['aid']; 印出來會是100)

◎POST:給表單傳值用的變數呼叫法

至於表單傳值就是form的用法了,
比方今天我們在網頁上插入一個表單,
要使用者輸入帳號密碼,

當他按送出之後,
表單欄位就會傳值,

比方:

帳號:__________ ←假設這個文字欄位叫u_name

密碼:__________ ←假設這個文字欄位叫u_psw

送出



等使用者按送出後,
要抓取到他輸入的值,
帳號那欄就是使用 $_POST['u_name']
同理,密碼那欄是 $_POST['u_psw']

假設使用者在 u_name 那欄輸入 belleaya
那在接收頁我們使用 echo $_POST['u_name'];
就可以印出 belleaya。





網站利用-facebook-帳號登入-(javascript-sdk)


facebook php  example....

https://developers.facebook.com/docs/reference/php

         FB.login(function (response) {
              if (response.authResponse) {
                     FB.api('/me', function (response) {
                           //所以 login 後可以直接取得下面的值,並傳入 CheckPlayer 這 function 
                           //然後在 CheckPlayer 中透過AJAX在資料庫中檢查並寫入資料庫
                           CheckPlayer(response.id, response.name, response.email,response.birthday);
                     });
               } else {
                    alert('登入失敗!');
               }
         }, {
                 scope: 'email,user_birthday'
         });
     }
});
function CheckPlayer(uid, cname, email, birthday) {
       $.ajax({
              url: 'AJAX/CheckGamePlayer.aspx',
              type: 'POST',
              data: { uid: uid, cname: cname, email: email, birthday: birthday },
              dateType: 'html',
              success: function () {
                    //檢查資料庫並新增完之後就看要幹嘛
               }
       })
}



Reference : http://sweeteason.pixnet.net/blog/post/37284400-%E7%B6%B2%E7%AB%99%E5%88%A9%E7%94%A8-facebook-%E5%B8%B3%E8%99%9F%E7%99%BB%E5%85%A5-(javascript-sdk)

2016年2月22日 星期一

更新 mysql 資料庫失敗

$sql = "update member_table set password=$pw, telephone=$telephone, address=$address, other=$other where username='$id'";


把update 資料庫的命令改成這樣...加上 '' ..

$sql = "update member_table set password='$pw', telephone='$telephone', address='$address', other='$other' where username='$id'";

用 jquery 來做 form 的驗證


用 jquery 來做 form 的驗證


Reference : http://www.sitepoint.com/basic-jquery-form-validation-tutorial/

2016年2月19日 星期五

php study ---- font --- draw

執行  php file....

php   index.php



PHP 支援八種基本型態 (primitive type)

這八種分別是
  • 布林 (boolean)
  • 整數 (integer)
  • 浮點數 (floating point number)
  • 字串 (string)
  • 陣列 (array)
  • 物件 (object)
  • 資源 (resource)
  • NULL
基本上程式 (program) 會自動判斷變數 (variable) 的資料型態 (data type) , PHP 的變數寫法就比較特別一點,用金錢符號 $ 開頭,其後可接英文字母,如下 $b 為布林型態, $i 為整數型態, $f 為浮點數型態, $s 為字串型態

$b = True; // 布林型態
$i = 1234; // 整數型態
$f = 12.3; // 浮點數型態
$s = "12"; // 字串型態

陣列就比較複雜一點,因為陣列分成兩部份,第一部分為索引,第二部份則是資料,兩者可以是上面四者型態任一,資料還可以是其他的陣列,例如
$a1 = array(10, 20, 30, 40);
$a2 = array(
    False => True,
    33 => "Tony",
    "A" => 33.06,
    6.32 => array(1, 2),
);
建立陣列需要用到內建函數 (function) array() ,索引與資料放在參數列 (parameter list) ,若無提供索引,如 $a1 ,索引會自動由 0 遞增填補,因此存取 $a1 如下
echo $a1[0];
echo $a1[1];
echo $a1[2];
echo $a1[3];

來個  imagettftext 的例子....

由於他需要  PHP GD2 library

sudo apt-get install php5-gd



<?php// Set the content-typeheader('Content-Type: image/png');// Create the image$im = imagecreatetruecolor(400, 30);// Create some colors$white = imagecolorallocate($im, 255, 255, 255);$grey = imagecolorallocate($im, 128, 128, 128);$black = imagecolorallocate($im, 0, 0, 0);imagefilledrectangle($im, 0, 0, 399, 29, $white);// The text to draw$text = 'Testing...';// Replace path by your own font path$font = 'arial.ttf';// Add some shadow to the textimagettftext($im, 20, 0, 11, 21, $grey, $font, $text);// Add the textimagettftext($im, 20, 0, 10, 20, $black, $font, $text);// Using imagepng() results in clearer text compared with imagejpeg()imagepng($im);imagedestroy($im);?>

改一下例子....

<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 400);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 399, $white);

// The text to draw
//$text = 'Testing...';
$text = '紀富中';
// Replace path by your own font path
//$font = '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf';
$font1 = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc';
$font2 = '/usr/share/fonts/truetype/wqy/wqy-microhei.ttc';

// Add some shadow to the text
//imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 30, 0, 40, 40, $black, $font1, $text);
imagettftext($im, 30, 0, 80, 80, $black, $font2, $text);
imagepng($im);
imagedestroy($im);
?>

執行結果如下 :


還有一些可以畫圖畫線的library....

http://jpgraph.net/download/
http://pydoing.blogspot.tw/2012/11/php-How-to-Execute.html

一些字型下載的網址
http://fonts.mobanwang.com/