1 / 50

CC510 Web Programming Ⅱ

CC510 Web Programming Ⅱ. -- PHP, Web Board – TA. Janghwan Lee T. 5584. <result source >. CGI / PHP. Connect to site. CGI program execute. PHP is similar to CGI in the structure It executes process not in HTML. Web Server. CGI application program. Web browser in PC.

Download Presentation

CC510 Web Programming Ⅱ

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. CC510Web Programming Ⅱ -- PHP, Web Board – TA. Janghwan LeeT. 5584

  2. <result source > CGI / PHP Connect to site CGI program execute • PHP is similar to CGI in the structure • It executes process not in HTML Web Server CGI application program Web browser in PC Transfer result by html Transfer html to browser html * PHP code “php test.php” <?echo"첫번째 프로그램";echo"아싸~";echo"날짜 : ".date("Y-m-d");?>

  3. What is PHP? • Server side script language • Execute in server and include html • When you change .html file to .php, you can also use it • Process automatically and represent the result • Need not change by user • E.g.) in previous page, without php, user need to change date everyday • Developed by Rasmus Lerdorf in 1994

  4. PHP in HTML example • In ex1.php • -line1~5, 7~8 : recognize as html • Line 6 : execute as php mode

  5. What can we do with PHP? • Can make CGI program(web application) • Support variable Databases and make web page using database • Adabas D InterBase Solid dBase mSQL Sybase • Empress MySQL Velocis FilePro Oracle Unix dbm • InformixPostgreSQL

  6. PHP grammar • php in html file • <? Echo (“very simple \n”); ?> • <?php echo(“ ….. \n”); ?> • php must have ‘;’ at the end of the line ex) <? echo “this is test.”; ?> (O) <? echo “if there is no semicolon” echo “error!”; ?> (X) – in one line, there must be 1 command  <? echo “if there is no semicolon”; echo “error!”; ?> (O)

  7. PHP grammar • Comments • Basically same as in C and perl • //, # , /* */ e.g.) <? echo “today <BR>"; // 2005-03-28 ?> <? echo “it’s warm<BR>"; # 한줄 주석 ^^ ?> <? echo “happy day~~! ^^<BR>";/* echo "아 여기부터는 주석처리되기 때문에 ";echo "결과에는 반영이 안되겠군요.. ㅜㅜ<BR>"; */ ?> • Comments in comments are not allowed e.g.) /* ~~~ /* ~~~ */ ~~~ */ (X)

  8. PHP grammar • Error message • Set in “C:\Program Files\PHP\php.ini” Display_errors = Off  Display_errors = ON Save this file and Restart apache server!! Edit like this!!

  9. PHP variables • Integer : $a = 1234; $a = -123; • Doubles : $a = 1.234; $a = 1.2e3; • String : “string” • “\n” : new line, “\\” : back slash (\) • “\t” : tab, “\”” : “ ex4.php) <?php $str = "문자열"; $str = $str . " 좀더 붙여서.."; $str .= " 나도 끼워줘~\n"; echo $str . "<BR>"; $num = 9; $str = "Number: $num"; echo $str . "<BR>"; $num = 9; $str = 'Number: $num'; echo $str . "<BR>"; ?>

  10. PHP variables • array • $a[0]=“abc”; $a[0][0]=“def”; $a[0][0][0]=“123”; • Need not declaration

  11. PHP variables • object • define using class • If you don’t know, you don’t need to learn it now • PHP variables • Php variables start with $ • Php variables consist of alphabet, number (case sensitive) • After $, there must be alphabet e.g.) $babo, $php4, $in_out_result (O) $babo?, $4abc, $in-out (X)

  12. PHP operator • <PHP operator> • +, -, *, /, % • <, >, <=, >=, ==, != <?echo"<h4>a++</h4>";$a=5;echo" \$a++: ".$a++."<br>\n";echo" \$a : ".$a."<br>\n";echo"<h4>++a</h4>";$a=5;echo" ++\$a: ".++$a."<br>\n";echo" \$a : ".$a."<br>\n";echo"<h4>=</h4>";$a=5; $b=$a; echo" \$a : ".$a."<br>\n";echo" \$b : ".$b."<br>\n";echo" \$a+$b : ".$a+$b."<br>\n"; echo"<h4>.</h4>";$a= ”hi”; $b = “!~~”; $c = $a.$b; $d= $c. “how are you”; echo" \$c: ".$c."<br>\n";echo" \$c+ : ".$d."<br>\n";?>

  13. PHP – control statements • if <? $a = 1; $b = 0; if ( $a > $b ) { //if $a>$b , execute next echo “a is bigger than b.”;     }elseif ($a == $b) { // if $a>$b is false and $a==$b, execute next echo “a is equal to b.”; } else { // if $a<$b , execute next echo “a is smaller than b.”; } ?>

  14. PHP – control statements switch (variable) { case value1: statement1 break; case value2: statement2 break; default : statement3 } If variable is value1, then run statement until when it meet ‘break’

  15. PHP – control statements • while (a) { b } • while a is true, execute b • do { a } while (b) • similar as while • run a and while b is true, execute a <?$i=1;while($i<=10){echo$i++;//$i }?>

  16. PHP – control statements • for(expr1; expr2; expr3) • Execute expr1 • If expr2 is true, run statement • After run all statements, execute expr3 e.g.) for ($i=1; $i <=10; $i++) {        echo $i;     }

  17. PHP – include • include(‘somefile.html’); • Somefile.html substitutes for the include statements

  18. PHP - require • require(‘somefile.html’); • the function is similar to the function of include • The difference between include and require • When it is in control statements • require execute all the time • Include execute when the statements is true

  19. PHP - form • <form name=“form name” action=“destination’s address” method=“transfer protocol> HTML … </form> • Method • Get : transfer by URL • /index.php?name=brown&homepage=http://… • ?variable_name=value • Post : transfer by HTTP header, more secure than get • <input> ex) <FORM ACTION=FILENAME METHOD=POST> <INPUT TYPE=TEXT> <INPUT TYPE=SUBMIT> </FORM>

  20. PHP - form • METHOD = POST or GET • POST : don’t represent data in URL • Good for security • GET : represent data in URL • Only limited string can transfer • ACTION = “file” • When input data fill, and click, then execute the contents in the file

  21. <FORM> tag Click here!!

  22. <FORM> tag

  23. PHP function - time • date() • Return date according to the requested form reference) http://kr.php.net/date

  24. PHP function - time • Microtime() • Return 2 values • Return microtime • return time in seconds since 1970. 1. 1 • Time() • return time in seconds since 1970. 1. 1

  25. PHP function - math • abs() : return absolute value • ceil() : return minimal integer which is bigger than the value • floor() : return maximum integer which is smaller than the value • round() : return the closest integer <?php $value = abs(-15); echo “$value<br>”; $value = ceil(31.2); echo “$value”<br>; $value = floor(31.2); echo “$value<br>”; $value = round(31.4); echo “$value<br>”; ?>

  26. PHP function - math • pow(a,b) : return ab • sqrt(a) : square root of a • log(a) : logea • log10(a) : log10a • pi() : 3.141592… • hexdec() : change hexadecimal value to decimal value • dechex() : change decimal value to hexadecimal value

  27. PHP function - math • rand(a,b) : make random number between a and b • srand() : initialize random seed • Srand(time())

  28. PHP function - file • fopen(file name, mode) : file open • fclose() : close file e.g.) $fp=fopen(“/home/etc/file.txt”, “r”); $fp=fopen(“http://www.php.net/”, “r”); $fp=fopen(“ftp://user:password@example.com/”, “w”); • file_exists() : if file exists, return 1, else return 0 • file() : get file information • $fcontents = file(‘http://www.php.net’);

  29. PHP function - file • fread(), fgets() • Read data from file • fwrite(), fputs() • Write data into file • feof() • Check if it is end of the file e.g.) fread <?php $filename = “/usr/local/something.txt”; $fd = fopen ($filename, “r”); $contents = fread ($fd, filesize ($filename)); fclose($fd); ?>

  30. Configuration file - PHP • php.ini • C:\Program Files\PHP\php.ini or C:\windows\php.ini • We need to change some configurations • short_open_tag = on ; <? also works instead of <?php

  31. Configuration file - Apache • httpd.conf • C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf • modify line • DirectoryIndex index.html index.php

  32. Configuration file • my.ini • Mysql configuration file • C:\Program Files\MySQL\MySQL Server 5.0\my.ini • To use gnuboard • sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION“ -> • #sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION“ • delete or insert comment mark • MySQL version lower than 5.0 doesn’t need this configuration.

  33. Counter • Program to represent the number of people connecting the homepage • General counter • counter increases whenever the page is opened • Cookie counter • Use cookie, counter increases when the browser is closed • Cookie : when you log-in a page one time, before the browser is closed or log-out, you don’t need to log-in again • Session counter • Use session, counter increases one time while the session is alive • Session : cookie doesn’t know when the user goes out without comments, session is automatically deleted after user goes out the site or use nothing for a long time • Not widely used yet

  34. Board • Needs server which supports PHP and MySQL • Guest and user’s can post articles, diaries, photos, etc. • There are some free web boards on the web sites e.g.) zeroboard, gnuboard

  35. Installing MySQL Administrator www.mysql.com 1) Click here 2) Click here 3) Click here download windows installer

  36. MySQL Administrator

  37. MySQL Administrator Create DB process

  38. MySQL Administrator Add User process

  39. MySQL Administrator Add User process

  40. MySQL Administrator Add User process at localhost

  41. MySQL Administrator Add User process at localhost

  42. Installing gnuboard • Create DB • Add user • grant privilege to access database • run and restart mysql

  43. Installing gnuboard • download gnuboard4.tgz (1.2M) from http://sir.co.kr/solution/gnuboard4/ • extract files into /htdocs/ • C:\Program Files\Apache Software Foundation\Apache2.2\htdocs • Access the file via web browser • http://localhost/gnuboard4

  44. Installing gnuboard • Database setting

  45. Board name Use gnuboard • Execute by TA • Using in homepage • Make HTML file using link the zeroboard • Link url http://localhost/gnuboard4/bbs/board.php?bo_table=main

  46. LAB #2 • Implement “Simple Calculator” web application on the Apache + PHP server. • “Simple Calculator” support 2 operands and 6 operations ( +, -, *, /, power, log) • The calculation result is show like following examples • Result page contains the link for file download the calculation result. • The calculation must be conducted on server using PHP • Hint : use <form> tag and POST method.

  47. LAB #2 (example)

  48. LAB #2 (example)

  49. Homework #1 1) Install apach, mysql, and php 2) Make one homepage to introduce yourself - which includes at least two web boards (e.g. Notice, Guest board…) - which has more than 3 pages - which has one download link for a file - each page must be linked together - use at least one frame - use at least one table • Using Namo Web editor or MS front page are not allowed • Hand in : Mail to TA Han Junhee(hanj@bulsai.kaist.ac.kr) • Contents • the homepage address and your student ID number and your name • Mail title must be • [CC510] homework #1_student number • Contents, design will not effect score • Due date is midnight(24:00) 22th March.

  50. Homework #1(in Korean) 1) apach, mysql, php를 설치하라 2) 자신을 주제로 한 개인 홈페이지를 만들어라. <조건> - 적어도 두개 이상의 게시판을 포함해야 한다. (예. 공지, 방명록,…) - Page는 3개 이상이어야 한다. - 적어도 하나의 download link가 있어야 하며, 파일을 download 받을 수 있어야 한다. - 각 페이지는 서로 link되어 있어야 한다. - 하나 이상의 frame을 사용하여야 한다. - 하나 이상의 table을 사용하여야 한다. • 나모 웹에디터나 프론트페이지 같은 홈페이지 작성 툴은 사용해서는 안됨 • 페이지의 내용과 디자인은 채점에 포함되지 않음. • 제출 : 조교에게 메일을 이용하여 제출. • 담당TA: 한준희(hanj@bulsai.kaist.ac.kr) • 메일내용 : 홈페이지 주소와 학번, 본인의 이름을 포함해야 한다. • 메일 제목은 다음과 같이 하여 보낸다. • [CC510] homework #1_학번 • 기한은 3월 22일 자정(24:00)까지

More Related