Your SlideShare is downloading. ×
0
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Dynamic Web Programming
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Dynamic Web Programming

5,416

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,416
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Dynamic Web Programming: Application and Transfer <br />
  • 2. Active Server Pages (ASP)<br />When a browser calls an ASP document, the ASP Server reads the .asp document and<br />Substitutes appropriate files for the (server-side) include statements<br />Runs the ASP code (Visual Basic Script – see the Tutorial and Language Reference, …)<br />Returns the resulting HTML code to the browser<br />Example (code, copy of database)<br />
  • 3. ASP Key Points (1)<br />ASP code enclosed in: &lt;% VBScript code %&gt;<br />Everything outside is HTML<br />The result of the combined HTML and ASP code must be a “standard” HTML document, e.g.:<br />&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Final//EN&quot;&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Miracle Drug Study&lt;/title&gt;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;&lt;meta name=&quot;Description&quot; content=&quot;&quot;&gt;&lt;meta name=&quot;Keywords&quot; content=&quot;&quot;&gt;&lt;link rel=STYLESHEET type=&quot;text/css&quot; href=&quot;&quot;&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;<br />
  • 4. ASP Key Points (2)<br />Connect with database:<br />Create connection object:<br />set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br />Open connection:<br />conn.open(&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:webdatabase escompstudy.mdb&quot;)<br />Submit a (read-only) Query:<br />Generate SQL statement:<br />SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = &apos;&quot; &amp; Gender &amp; &quot;&apos; ORDER BY FirstName DESC&quot;<br />set Patients = conn.execute(SQL)<br />
  • 5. ASP Key Points (3)<br />Move through the data records:<br />do while NOT Patients.eof Name = Patients(0) &amp; &quot; &quot; &amp; Patients(1) Patients.MoveNextloop<br />Add to or edit table:<br />Create and open Record Set object:<br />set RS = Server.CreateObject(&quot;ADODB.Recordset&quot;)RS.Open “table name&quot;, conn, , adLockOptimistic, adCmdTable(where adLockOptimistic = 3, adCmdTable = 2)<br />
  • 6. ASP Key Points (4)<br />Add to or edit table (continued):<br />Create new record, Edit, &amp; Update:<br />RS.AddNewRS(“Dosage”) = 200RS.Update<br />Or Find desired record, Edit, &amp; Update :<br />do while NOT RS.eof if RS(“ID”) = 7 then RS(“Dosage”) = 200 RS.Update else RS.MoveNext end ifloop<br />
  • 7. ASP Key Points (5)<br />Clean up (free server resources) when done:<br />Queries:<br />Patients.Closeset Patients = nothing<br />Record Sets:<br />RS.Closeset RS = nothing<br />The Connection:<br />conn.closeset conn = nothing<br />
  • 8. ASP Security<br />Apart from various Internet Information Services (IIS – Window’s Web service) security holes (for viruses and worms), security is quite good.<br />Use https:// if you want to protect content over the internet – provides Secure Socket Layer (SSL) security<br />
  • 9. ASP Resources<br />ASP Introduction<br />Microsoft’s VBScript Tutorial &amp; Language Reference (also here)<br />WebMonkey’s tutorial<br />
  • 10. ColdFusion<br />Easy-to-learn Server-Side Scripting Language: CFML, or Cold Fusion Markup Language, is embedded in HTML code<br />CF code is enclosed in or by CF tags:<br /> &lt;CFtagnameCF code &gt;<br />&lt;Cftagname &gt; CF Code &lt;/Cftagname &gt;<br />Documents must end in .cfm<br />ColdFusion is Case Insensitive<br />Example (code, copy of database)<br />
  • 11. ColdFusion Key Points (1)<br />All #variables# are enclosed in # signs<br />HTML output which includes of CF variables must be surrounded by CF output tags; e.g.:<br />&lt;Cfset height = “tall”&gt;&lt;CFoutput&gt;The &lt;B&gt;#height#&lt;/B&gt; boy fell.&lt;Cfoutput&gt;<br />
  • 12. ColdFusion Key Points (1)<br />Connect with database and run query simultaneously:<br />&lt;CFQUERY Name=&quot;Patients&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;&gt;SELECT ID, FirstName, LastName FROM PatientsORDER BY FirstName&lt;/CFQUERY&gt;<br /> Where the variables are defined beforehand:<br />&lt;CFset Dbdriver = &quot;Driver={MICROSOFT ACCESS DRIVER (*.mdb)}; UID=admin; PWD=; dbq=&quot;&gt;<br />&lt;CFset Dbfile = &quot;f:webdatabase escompstudy.mdb&quot;&gt; <br />
  • 13. ColdFusion Key Points (2)<br />Access Query Results<br />&lt;SELECT name=&quot;PatientID&quot;&gt;&lt;CFoutput QUERY=&quot;Patients&quot;&gt; &lt;OPTION value=#ID#&gt;#FirstName# #LastName#&lt;/CFoutput&gt;&lt;/SELECT&gt;<br />Insert Data from a Form<br />If a HTML form submits variables to be inserted, do so directly using CFinsert:<br />&lt;CFinsert tablename=&quot;Treatment&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;&gt;<br /> All variables in the form object (e.g. Form.var1) that match attributes in the table are inserted into the table automatically<br />
  • 14. ColdFusion Key Points (3)<br />Insert Data using Cfquery (SQL):<br />&lt;CFquery name=&quot;Treatment&quot; dbtype=&quot;dynamic&quot; connectstring=&quot;#DBdriver# #DBfile#&quot;&gt;INSERT into TreatmentVALUES (#PatientID#, #EventID#, Now(), #Dosage(mg)#, #Severity#, #Time#)&lt;/CFquery&gt;<br />Other Data editing features also available; see documentation<br />
  • 15. Cold Fusion Resources<br />Cold Fusion Introduction<br />Allaire/Macromedia’s Documentation Web page <br />Developing CF Applications<br />CFML Reference<br />CFML Quick Reference<br />WebMonkey’s tutorial<br />Security links page<br />
  • 16. Practical Extraction andReport Language (Perl)<br />Ubiquitous<br />Originally designed to be a better general purpose tool than a Unix shell, it has grown and spread to be supported from Windows to Macintosh to VMS.<br />Powerful but Cryptic<br />Example (code)<br />
  • 17. Perl Key Points (1)<br />The file itself must end in “.cgi” or “.pl”<br />First linemust specify the location of the Perl engine (The DBI module will not work for “#!/usr/local/bin /perl[5]” – see below):<br />#!/uva/bin/perl -w<br />First printed line must be the following if you want its response to go to a browser:<br />print &quot;Content-type: text/html &quot;;<br />
  • 18. Perl Key Points (3)<br />Set the usual parameters:<br />my $hostname = “lebec.tc.edu&quot;; my $username = “gordie&quot;; # &quot;my&quot; defines a local variablemy $password = “mine122&quot;;my $database = $username . &quot;_study&quot;; # = dld5s_studymy $data_source = &quot;DBI:mysql:$database:$hostname&quot;;<br />Connect to the database:<br />my $dbh = DBI-&gt;connect($data_source, $username, $password)or die &quot;Can&apos;t connect to $data_source: $DBI::errstr &quot;;<br />
  • 19. Perl Key Points (4)<br />Define the SQL statement and execute<br />my $SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = &apos;$Gender‘ ORDER BY FirstName DESC&quot;;my $sth = $dbh-&gt;prepare($SQL)or die &quot;Unable to prepare $SQL: dbh-&gt;errstr &quot;;$sth-&gt;execute or die &quot;Unable to execute query: $dbh-&gt;errstr &quot;;<br />Clean up<br />$sth-&gt;finish;$dbh-&gt;disconnect;<br />
  • 20. Perl Resources<br />Perl Programming Introduction<br />Perl Programming for the Web<br />Perl Documentation<br />Overview, Built-in functions, Data types, Regular expressions, …<br />Modules: DBI(1), DBI(2), CGI<br />WebMonkey’s Tutorial, etc.<br />MySQL and PERL for the Web by DuBois (New Riders)<br />Learning Perl by Schwartz &amp; Christiansen (O’Reilly)<br />Programming Perl by Wall, Orwant, &amp; Christiansen (O’Reilly)<br />Programming the Perl DBI: Database Programming with Perl by Descartes, Bunce, &amp; Mui (Editor) (O’Reilly)<br />
  • 21. PHP<br />Example<br />Add Source<br />Index Source<br />
  • 22. PHP: Hypertext Preprocessor (PHP)<br />HTML embedding scripting language (see the PHP online manual<br />When a browser calls a PHP document, the Server reads the PHP document and<br />Runs the PHP code<br />Returns the resulting HTML code to the browser<br />Example (code)<br />
  • 23. PHP Key Points (1)<br />Filename must end in .php or .phtml<br />PHP code enclosed in &lt;?php PHP code ?&gt; or &lt;? PHP code ?&gt;<br />Everything outside is HTML<br />Output is (generally) to a browser requiring standard HTML<br />
  • 24. PHP Key Points (2)<br />Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions<br />Connect with MySQL RDBMS<br />mysql_connect($hostName, $userName, $password) or die(&quot;Unable to connect to host $hostName&quot;);<br />Connect with database<br />mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;);<br />
  • 25. PHP Key Points (3)<br />Queries: Nearly all table interaction and management is done through queries:<br />Basic information searches<br />$SQL = &quot;SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = &apos;$Gender‘ ORDER BY FirstName DESC&quot;;$Patients = mysql_query($SQL);<br />Editing, adding, and deleting records and tables<br />$SQL = &quot;INSERT INTO Patients (FirstName, LastName) VALUES(&apos;$firstName&apos;, &apos;$lastName&apos;)&quot;;$Patients = mysql_query($SQL);<br />
  • 26. PHP Key Points (4)<br />Cleaning up: close the database connection<br />mysql_close();<br />
  • 27. PHP/MySQL Security<br />The same problems as PHP occur with Perl if you run it as a Perl or CGI script. <br />See the passwords link<br />
  • 28. PHP Resources<br />PHP and MySQL<br />PHP Documentation<br />PHP’s Tutorial<br />WebMonkey’s Tutorial<br />PHP and MySQL Web Development by Welling &amp; Thomson (SAMS)<br />Beginning PHP4 by Blan, Choi, et. al (Wrox)<br />
  • 29. (Other) Books<br />MySQL by DuBois (New Riders)<br />MySQL and PERL for the Web by DuBois (New Riders)<br />MySQL &amp; mSQL byYarger, Reese, &amp; King<br />PHP and MySQL Web Development by Welling &amp; Thomson (SAMS)<br />Beginning PHP4 by Blan, Choi, et. al (Wrox)<br />Learning Perl by Schwartz &amp; Christiansen (O’Reilly)<br />Programming Perl by Wall, Orwant, &amp; Christiansen (O’Reilly)<br />Programming the Perl DBI: Database Programming with Perl by Descartes, Bunce, &amp; Mui (Editor) (O’Reilly)<br />SQL-99 Complete, Really by Gulutzan &amp; Pelzer (R&amp;D Books)<br />
  • 30. PHP<br />PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.<br />PHP is a project of the Apache Software Foundation. <br />PHP stands for PHP: Hypertext Preprocessor.<br />
  • 31. Let’s get started.<br />As we already said PHP can be embedded into HTML:<br />#!/usr/local/bin/php<br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;?php<br /> echo “Hello I am a PHP script”;<br />?&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br />
  • 32. First file<br />Save the file with a PHP extension in your public_html folder.<br />Give the webserver execute permission (chmod 755 hello.php is the easiest way to do this)<br />Point a webserver at the file<br />Let’s look at the first line of the file<br />#!/usr/local/bin/php<br />
  • 33. Something more Useful<br />&lt;?php<br /> echo $_SERVER[&quot;REMOTE_ADDR”]; <br />?&gt;<br />What is echo(); ?<br /> echo() is a PHP function which prints output to the webpage, php has many functions that do this, print(), printf() are two examples.<br />What is $_SERVER?!<br />$_SERVER is a special reserved PHP variable that contains all web server information. It&apos;s known as an Autoglobal (or Superglobal).<br />
  • 34. Mixin and matchin PHP &amp; HTML<br />&lt;?php <br />if (strstr($_SERVER[&quot;HTTP_USER_AGENT&quot;], &quot;MSIE&quot;)) {<br />?&gt;<br />&lt;h3&gt;strstr must have returned true&lt;/h3&gt;<br />&lt;center&gt;&lt;b&gt;You are using InternetExplorer&lt;/b&gt;&lt;/center&gt; <br />&lt;?php <br />} else { ?&gt; <br />&lt;h3&gt;strstr must have returned false&lt;/h3&gt; &lt;center&gt;&lt;b&gt;You are not using Internet Explorer&lt;/b&gt;&lt;/center&gt; <br />&lt;?php } ?&gt;<br />Here we see you can mix and match HTML and PHP together, this is because PHP does the PHP bit first, it’s output is HTML and then bangs all the HTML together.<br />
  • 35. PHP Forms<br />Forms are a useful part of any internet site, and I’m sure you’ve used them in the past. Forms are part of HTML, however you can pass their values to a PHP script. Here is a simple HTML form which you can put in any HTML file:<br />&lt;form action=&quot;action.php&quot; method=&quot;POST&quot;&gt; <br />Your name: &lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;<br />Your age: &lt;input type=&quot;text&quot; name=&quot;age&quot;&gt; <br />&lt;input type=&quot;submit&quot;&gt; <br />&lt;/form&gt;<br />This isn’t specific to PHP, the only thing to notice is how we pass the values to “action.php”<br />
  • 36. Handling POST data<br />Now we edit action.php (of course this file can be called whatever, as long as the form passes it on).<br />Hi &lt;?php echo $_POST[&quot;name&quot;]; ?&gt;.<br />You are &lt;?php echo $_POST[&quot;age&quot;]; ?&gt; <br />years old.<br />
  • 37. Handling POST data<br />$_POST[] is an autoglobal array which get’s created at every webpage by the server.<br />Sample out put from our script would be:<br />Hi Joe. You are 22 years old<br />
  • 38. Data Types<br />There are eight data types in PHP (which isn’t a lot), I’m going to cover three, the others are not used a lot and would be considered advanced in the contexts of PHP anyways. Data types in PHP, unlike, are flexible or not strict, and are refrenced the same way, so inter-chaging is simple.<br />
  • 39. Data Types<br />$bool = TRUE; // a boolean <br />$str = &quot;foo&quot;; // a string <br />$int = 12; // an integer <br />echogettype($bool); // prints out&quot;boolean&quot; <br />echo gettype($str); // prints out &quot;string&quot; <br />// If this is an integer, increment it by four<br />if (is_int($int)) { $int += 4; }<br /> /* If $bool is a string, print it out (does not print out anything) */<br />if (is_string($bool)) { <br />echo &quot;String: $bool&quot;; <br />}<br />
  • 40. Manulipating Data Types<br />These types can be added, subtracted, concatinated like they can be in C or Java<br />$a = 5;<br />$b = 4;<br />Echo ($a + $b); // prints 9!<br />$string = “touch”;<br />$end = “down”;<br />Echo $string.$end; //prints touchdown!<br />
  • 41. Control Structures<br />If:<br />$hey = TRUE;<br />If($hey) {<br /> printf(“Hello ”);<br />} else {<br /> printf(“Never gona see this! ”);<br />}<br />
  • 42. While<br />$a = 0;<br />While($a &lt; 100) {<br /> printf(“hello $a ”);<br /> a++;<br />}<br />Prints all the numbers from 0 to 99.<br />
  • 43. For &amp; others<br />For($a = 0; $a &lt; 100; $a++){<br /> printf(“Hello $a ”);<br />}<br />//prints all the numbers from 0 to 99 again<br />PHP has also all the other control structures you can think of, until, do, switch, : ? <br />
  • 44. Global Variables<br />We’ve already seen the use of some global or Super variables in $_POST and $_SERVER. There’s a good few of them which can be useful to make your site more personal. To get a list of them, create this PHP file.<br />#!/usr/local/bin/php<br />&lt;?php phpinfo(); ?&gt;<br />
  • 45. Resources<br />This helpdesk tutorial like the others is just geared to get you started at PHP coding. PHP’s website is the best resource for consultation, www.php.net it has a simple to follow tutorial (you might find striking resemblances with tonite’s!), as well as a manual page for every function in PHP. I recommend you go to the site for more detailed descriptions of what we did tonite.<br />
  • 46. Why is PHP good?<br />Php is good for a number of reasons<br />Easy to use<br />Well documented<br />Large library<br />Good Database interaction<br />Good for Projects!!<br />See Paul Acquaro’s class this Summer.<br />

×