1 / 30

Lesson 4: http 概觀與資料分析粹取 (2004/09/09)

Lesson 4: http 概觀與資料分析粹取 (2004/09/09). 講員介紹. 本名:孫仲岳 (Saturn Sun.) 生日: 1980 年 11 月 4 日天蠍座 現任: 彰化市社區大學 講師 中原大學校園網路策進會 創會會長 中原檔案伺服器網管 http://ftp.cycu.edu.tw 中原熊蓋站站長 http://best .cycu.edu.tw 中文化軟體聯盟網管 http://cpatch.org AX 工作室負責人 http://www. ax.com.tw. 如何取得上課投影片.

yamin
Download Presentation

Lesson 4: http 概觀與資料分析粹取 (2004/09/09)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 4: http概觀與資料分析粹取 (2004/09/09)

  2. 講員介紹 • 本名:孫仲岳 (Saturn Sun.) • 生日:1980年11月4日天蠍座 • 現任: • 彰化市社區大學 講師 • 中原大學校園網路策進會 創會會長 • 中原檔案伺服器網管 http://ftp.cycu.edu.tw • 中原熊蓋站站長 http://best.cycu.edu.tw • 中文化軟體聯盟網管 http://cpatch.org • AX工作室負責人 http://www.ax.com.tw

  3. 如何取得上課投影片 • http://best.cycu.edu.tw • 進入「校園網路策進會」版

  4. 網頁資訊處理 • 透過php,抓取網頁資料再處理 • 範例: • 瀏覽Y新聞(用瀏覽器) • 瀏覽Y新聞(用PHP) • 處理Y新聞(用PHP) • 顯示Y新聞(用PHP)

  5. 網頁資訊處理 • 隱藏不顯示的內容 • <!-- 內容 --> • <noscript> 內容 </noscript> • <noframe> 內容 </noframe> • 運用 str_replace() • 範例: • $bufffer = str_replace(搜尋字串,替換字串, $bufffer)

  6. 網頁資訊處理 • 動動手時間 • 找一個網頁來開刀^^ • 去除他的廣告 • 替換連結(修正超連結) • http://www.cycu.edu.tw/cycu/chinese/home.htm • 如果不想自己找,就改上面這個吧!^^

  7. HTTP 協定介紹 • HTTP/1.0 • 定義於 RFC 1945 • HTTP/1.1 • 定義於 RFC 2616 • RFC (Request for Comment)文件 • http://ftp.isu.edu.tw

  8. HTTP 協定介紹 • 差異點: keep-alive 的支援 • 1.0 版 • 做完請求後,會自動切斷連線 • 1.1 版 • 在做完請求後,仍會保持連線狀態

  9. HTTP 協定介紹 • Keep-alive 的好處 • 節省重複建立連線的頻寬與時間 • Keep-alive 的缺點 • 多工處理較為複雜 • 較難將一個連線發揮到最大效用

  10. HTTP 協定介紹 • Request Mode • GET • 一般瀏覽網頁均屬此種模式 • 早期有資料附掛的長度限制 • POST • 常用於表單 (form) 送出 (submit) • 可以設定多種類型,做純文字傳輸檔案傳輸

  11. HTTP 協定介紹 • <form method="POST" action="網頁"> • …表單內容 • …表單內容 • </form>

  12. URL 格式 • http_URL = • "http://host [ ":" port ] [ abs_path [ "?" query ]] • host: 不分大小寫 (case-insensitive) • abs_path: 沒有指定就等於 “/” • 預留字處理: %HEX HEX • 例: http://ABC.com/%7Esmith/home.html

  13. URL 格式 • http://ok.com.tw:999/path/xxx.php • ?name1=value1&name2=value2 • http 協定類型 • ok.com.tw 主機 • 999 連接埠 • /path/xxx.php 目標檔案

  14. GET 範例 • GET / HTTP/1.1 • Host: www.cycu.edu.tw • Accept: */* • Referer: http://www.cycu.edu.tw • User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98) • Pragma: no-cache • Cache-Control: no-cache • Connection: close

  15. GET 範例 • HTTP/1.1 200 OK • Date: Wed, 11 Feb 2004 20:44:04 GMT • Server: HP Apache-based Web Server/1.3.26 (Unix) • Last-Modified: Mon, 14 Jan 2002 08:48:22 GMT • ETag: "10b7a-13e-3c429b56" • Accept-Ranges: bytes • Content-Length: 318 • Connection: close • Content-Type: text/html

  16. HTTP 之 header • 可以利用PHP來傳送header • 模擬瀏覽器與伺服器端的溝通 • 函式 header(); • 注意事項: 使用header 不可以echo資料

  17. header 效果測試 • 自動換頁 • header ("Location: http://www.php.net"); • exit; • 騙人家找不到網頁 • header ("HTTP/1.0 404 Not Found"); • exit;

  18. header 效果測試 • 強迫不要使用快取(cache) • header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); • header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); • header("Cache-Control: no-cache, must-revalidate"); • header("Pragma: no-cache"); • 設定檔案類型 • header("Content-Type: image/jpeg"); • 更多資料可以上 www.php.net搜尋

  19. Cookie • Cookie 原理 • 透過網頁程式送出資訊給瀏覽器儲存 • 下次瀏覽再將資訊原封不動送給程式 • 由程式因應送回的資訊作不同的動作。 • 詳情請參閱:RFC 2109

  20. Session • 程式將 Client 資訊儲存於 Server 端,並發給一組 Cookie 資訊。 • 使用者藉由這組 Cookie 資訊送給 Server,Server 便得以透過這組 Cookie 來取得先前儲存的資料。 • 藉由 Cookie 的應用達到一個連線期的效果。

  21. Cookie 進階 • Server 會送出一組 Header • Cookie: var1=val1; var2=val2 … • Client 將這個 Header 儲存下來 • 下次要求該網頁的時候,加送Header • Set-Cookie: var1=val1; var2=val2 … • 如此就完成 Cookie 的使用了

  22. 登入與查詢實作 • 範例 • 修課清單查詢(資訊查詢系統) • 修課清單查詢(選課系統) • 修改 • 找尋學校中的其中一個登入系統 • 用php代替使用者登入查詢

  23. fsockopen() • 開啟一個連線。 • fput() • 送出一行字串。 • fgets() • 取得一行字串。 • fclose() • 關閉連線。

  24. 相關 RFC 文件 • RFC 1945 • Hypertext Transfer Protocol -- HTTP/1.0 • RFC 2068 • Hypertext Transfer Protocol -- HTTP/1.1 • RFC 2109 • HTTP State Management Mechanism • …

  25. 小結 • 相信上完了今天的課程 • 您已經對HTTP應用有了一針見血的了解 • 視情況需要做網頁的擷取、分析 • 異質資料庫、不易取得的資料 • 抓取氣象、新聞、選課資料 • 跨平台擷取資料 • 不需要經過DB,可以即時配合處理

  26. 作業 • 把修課清單查詢作修改 • 改成成績查詢 • 或是監考查詢 • 編輯頁面 • 找出變數值、目標頁面 • 進行連線、POST 資料

  27. 特別致謝 & 版權聲明 • 其中部分解說,參考引用義守資工所 郭東黌(KTH)所撰之文件,特此感謝。 • 本投影片中提及的網址,版權歸其所屬公司所有。

  28. 參考網站 • PHP Bible • http://dslab.csie.ncu.edu.tw/~happyman/book/cphp3/index.php.htm • PHP 官方網站 • http://www.php.net • Google • http://www.google.com.tw

  29. 下一份講義 • PHP架站機導覽 –9/6 • 樣板化程式寫作–9/7 • 模組化程式寫作–9/8 • HTTP概觀與資料分析粹取–9/9 • PHP Team Work 概念導引–9/10

  30. 謝謝各位 • 有任何疑問,聯絡請洽: • http://best.cycu.edu.tw 中原熊蓋站 - 公用討論區 • 寫信給我: • saturn@cna.cycu.edu.tw • saturn@ax.com.tw • 電話聯絡: • 0928-389698

More Related