Pages

Subscribe:

Ads 468x60px

Labels

顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2015年11月26日 星期四

Cent OS 7 安裝

這兩天架了一台Cent OS7的主機,我發現變化有點大。還好透過Google大神幫助找到幾篇文章,終於協助我將網站架設起來,並且啟動個人網站。

安裝重點可以參考
1.http://myip.tw/itsmw/index.php?title=CentOS7

重點是將SeLinux關閉

2.http://tech.hitsug.net/?CentOS-7%2FApache%2F%E8%A8%AD%E5%AE%9A
個人網站的開啟不再是透過http.conf
這篇資料提供設定的方式,調整後就可以正常運作

3.安裝webmin
這還是很重要的,另外CentOS7多了firewallD
透過這個來設定開放的Port
還有網路的設定必須啟動時就啟動網路設備
不然網路就不通了



2015年9月3日 星期四

Using ODBC with PHP

資料來源


Using ODBC with PHP ODBC is one of Microsoft's earliest technologies for connecting to databases. It is very popular and widely used. This article describes how to setup and use ODBC from a PHP perspective.
Also see DSN-less connections with PHP.

What is ODBC?

Open DataBase Connectivity is an Application Programming Interface (API) that allows a programmer to abstract a program from a database. When writing code to interact with a database, you have to add code that talks to a particular database using a proprietary API. If you want your program to talk to an Access, FoxPro and Oracle databases you have to code your program with three different database API's. This can be quite the daunting task causing much grief. Now, enter ODBC...
When programming to interact with ODBC you only need to use the ODBC API (a combination of ODBC extension function calls and the SQL language) to talk to different database products. The ODBC Manager will figure out how to contend with the type of database you are targeting. Regardless of the database type you are using, all of your calls will be to the ODBC API. All that you need to do is have installed an ODBC driver that is specific to the type of database you will be using.

Creating A ODBC Data Source Name (DSN)

After you have ensured that the ODBC driver for your database is installed, you normally need to create a Data Source Name (DSN), which contains all the connection details required to login (accept maybe id and password).
Walkthrough: How to Setup a DSN. A pictorial step-by-step guide. The next button is hidden on the bottom-right. Sorry but we Windows programmers are not user interface experts ;-)

Connecting to ODBC

There is an excellent tutorial on using PHP's ODBC extension at ASPToday, a popular ASP web site.
An example taken from the above article:

# query the users table for name and surname
$query = "SELECT name, surname FROM users";
# perform the query $result = odbc_exec($connect, $query);
# fetch the data from the database while(odbc_fetch_row($result)){ $name = odbc_result($result, 1); $surname = odbc_result($result, 2); print("$name $surname\n"); }
# close the connection odbc_close($connect); ?>

2015年9月2日 星期三

Apache 整合 Acitve Directory 達成 one single signon


我的公司使用AD進行使用者驗證,因此在使用者操作的便利性考量前提下.如何讓使用者不需要重覆輸入帳號與密碼,而直接抓取使用者已經登入AD的帳號資訊,已經變成系統開發必須要考量的項目之一 (至少我自己是這樣認為啦 @@)
.NET整合AD的資訊已經有大大實做成功並且實際運用於目前的系統上.由於都是微軟家族的產品,因此整合上比較容易.
但是目前公司存在有Apache+PHP+MySQL on Windows的架構,因此如何讓這樣的架構也可以快速的抓取使用者AD資訊是我今天要介紹的項目.
[版本需求]
1. Apache 2.x 以上
2. PHP和MySQL都沒有特殊的版本要求,不過我還是建議安裝PHP 5.x和MySQL 4.1.x以上的版本
[安裝過程]
1. 將mod_auth_sspi.so (下載位址)放到path_to_apache/modules這個目錄下面
2. 在httpd.conf裡面加上下面兩段
  (1) LoadModule sspi_auth_module modules/mod_auth_sspi.so
  (2)在需要進行驗證的目錄設定加上下面的內容,並且將AllowOverride開啟
      AuthName "A Protected Place"
      AuthType SSPI
      SSPIDomain tpe.compalcomm.com
      SSPIAuth On
      SSPIAuthoritative On
      SSPIOfferBasic On
      require valid-user
          
    修改後應該會像這樣
   
     Options Indexes FollowSymLinks
     AllowOverride All
     Order allow,deny
     Allow from all
     AuthName "A Protected Place"
     AuthType SSPI
     SSPIDomain tpe.compalcomm.com
     SSPIAuth On
     SSPIAuthoritative On
     SSPIOfferBasic On
     require valid-user
 

3. 重新啟動Apache
[如何抓取使用者登入AD的帳號]
程式只有一行,真的只有一行.
$_SERVER["REMOTE_USER"] 就只需要這行就可以抓到使用者登入AD的帳號.
後面要怎麼達成one single signon,我相信各位程式高手都知道該怎麼做了,我就不獻醜了.
[如何抓取使用者在AD中的其他資訊]
我之前有找到一個adLDAP.php的class,只需要確定ldap_binding正常,
然後將剛剛抓到的使用者AD帳號傳進去,AD裡面所有的資訊全部都可以抓出來.
adLDAP http://adldap.sourceforge.net/

2015年7月15日 星期三

[PHP][轉] 四捨五入,無條件進位, 無條件捨去

取整數函數

round($n)  四捨五入
ceil($n)   無條件進位
floor($n)  無條件捨去
php裏面轉換大小寫strtolower() , strtoupper()
mysql裏面轉換大小寫 ucase() , lcase() 
--

2015年5月21日 星期四

2015年5月6日 星期三

[PHP] 取得生日對應的星座名稱

ㄟㄟ
無意間找到這個
覺得很實用

資料來源

在 Google 上找了一下能用 function,花了十分鐘決定自己寫了,說實在的在 social 的網站上這算是基本需求,而以前寫的也不知道丟哪去了,這次好好記錄下來免得以後又要再寫一份。

  1. function getStarSignsName($month$day) {  
  2.    $list=array(  
  3.        array('name'=>"摩羯座",'min'=>'12-22','max'=>'01-19'),    
  4.        array('name'=>"水瓶座",'min'=>'01-20','max'=>'02-18'),  
  5.        array('name'=>"雙魚座",'min'=>'02-19','max'=>'03-20'),  
  6.        array('name'=>"牡羊座",'min'=>'03-21','max'=>'04-19'),  
  7.        array('name'=>"金牛座",'min'=>'04-20','max'=>'05-20'),  
  8.        array('name'=>"雙子座",'min'=>'05-21','max'=>'06-21'),  
  9.        array('name'=>"巨蟹座",'min'=>'06-22','max'=>'07-22'),  
  10.        array('name'=>"獅子座",'min'=>'07-23','max'=>'08-22'),  
  11.        array('name'=>"處女座",'min'=>'08-23','max'=>'09-22'),  
  12.        array('name'=>"天秤座",'min'=>'09-23','max'=>'10-23'),  
  13.        array('name'=>"天蠍座",'min'=>'10-24','max'=>'11-22'),  
  14.        array('name'=>"射手座",'min'=>'11-23','max'=>'12-21'),  
  15.    );   
  16.      
  17.    $time=strtotime("1970-$month-$day");  
  18.    foreach ($list as $row){  
  19.        $min=strtotime("1970-".$row['min']);  
  20.        $max=strtotime("1970-".$row['max']);  
  21.        if($min<=$time && $time<=$max){  
  22.            return $row['name'];  
  23.        }  
  24.    }  
  25.    /*other to 摩羯座*/  
  26.    return $list[0]['name'];  
  27. }  


測試程式:
  1. $test=array(  
  2.    array('n'=>"水瓶座",'m'=>'01','d'=>'20'),  
  3.    array('n'=>"水瓶座",'m'=>'02','d'=>'08'),  
  4.    array('n'=>"水瓶座",'m'=>'02','d'=>'18'),  
  5.      
  6.    array('n'=>"雙魚座",'m'=>'02','d'=>'19'),  
  7.    array('n'=>"雙魚座",'m'=>'03','d'=>'10'),  
  8.    array('n'=>"雙魚座",'m'=>'03','d'=>'20'),  
  9.      
  10.    array('n'=>"牡羊座",'m'=>'03','d'=>'21'),  
  11.    array('n'=>"牡羊座",'m'=>'04','d'=>'09'),  
  12.    array('n'=>"牡羊座",'m'=>'04','d'=>'19'),  
  13.      
  14.    array('n'=>"金牛座",'m'=>'04','d'=>'20'),  
  15.    array('n'=>"金牛座",'m'=>'05','d'=>'10'),  
  16.    array('n'=>"金牛座",'m'=>'05','d'=>'20'),  
  17.      
  18.    array('n'=>"雙子座",'m'=>'05','d'=>'21'),  
  19.    array('n'=>"雙子座",'m'=>'06','d'=>'1'),  
  20.    array('n'=>"雙子座",'m'=>'06','d'=>'21'),  
  21.      
  22.    array('n'=>"巨蟹座",'m'=>'06','d'=>'22'),  
  23.    array('n'=>"巨蟹座",'m'=>'07','d'=>'02'),  
  24.    array('n'=>"巨蟹座",'m'=>'07','d'=>'22'),  
  25.      
  26.    array('n'=>"獅子座",'m'=>'07','d'=>'23'),  
  27.    array('n'=>"獅子座",'m'=>'08','d'=>'02'),  
  28.    array('n'=>"獅子座",'m'=>'08','d'=>'22'),  
  29.      
  30.    array('n'=>"處女座",'m'=>'08','d'=>'23'),  
  31.    array('n'=>"處女座",'m'=>'09','d'=>'02'),  
  32.    array('n'=>"處女座",'m'=>'09','d'=>'22'),  
  33.      
  34.    array('n'=>"天秤座",'m'=>'09','d'=>'23'),  
  35.    array('n'=>"天秤座",'m'=>'10','d'=>'03'),  
  36.    array('n'=>"天秤座",'m'=>'10','d'=>'23'),  
  37.      
  38.    array('n'=>"天蠍座",'m'=>'10','d'=>'24'),  
  39.    array('n'=>"天蠍座",'m'=>'11','d'=>'02'),  
  40.    array('n'=>"天蠍座",'m'=>'11','d'=>'22'),  
  41.      
  42.    array('n'=>"射手座",'m'=>'11','d'=>'23'),  
  43.    array('n'=>"射手座",'m'=>'12','d'=>'02'),  
  44.    array('n'=>"射手座",'m'=>'12','d'=>'21'),  
  45.      
  46.    array('n'=>"摩羯座",'m'=>'12','d'=>'22'),  
  47.    array('n'=>"摩羯座",'m'=>'01','d'=>'09'),  
  48.    array('n'=>"摩羯座",'m'=>'01','d'=>'19'),  
  49. );  
  50.   
  51. foreach ($test as $v){  
  52.    if(getStarSignsName($v['m'],$v['d'])!==$v['n']){  
  53.        echo $v['n'],"error
    "
    ;  
  54.    }else{  
  55.        echo $v['n'],"OK
    "
    ;  
  56.    }  
  57. }