Server side basics CS382 1. URLs and web servers  Usually when you type a URL in your browser:  Your computer looks up the server's IP address using.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Server-Side vs. Client-Side Scripting Languages
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Server side basics.
Server side basics CS URLs and web servers  Usually when you type a URL in your browser:  Your computer looks up the server's IP address using.
CMPT241 Web Programming Intro to PHP.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
CSE 154 LECTURE 6: EMBEDDED PHP. PHP syntax template HTML content HTML content HTML content... PHP any contents of.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
INTERNET APPLICATION DEVELOPMENT For More visit:
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Nael Alian Introduction to PHP
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Tutorial 10 Programming with JavaScript
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Introduction to PHP.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CSE 154 LECTURE 14: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
CSE 154 LECTURE 15: EMBEDDED PHP. PHP syntax template HTML content HTML content HTML content... PHP any contents of.
PHP. What is PHP? PHP Hypertext Processor – Dynamic web development – Scripting language – Can be procedural or OOP(preferred) – PHP code can be embedded.
PHP using MySQL Database for Web Development (part II)
PHP for Server-Side Programming
Tutorial 10 Programming with JavaScript
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 6 PHP & MySQL Li Xu
CMPT241 Web Programming Intro to PHP.
Lecture 14: JSON and Web SERVICES
PHP an introduction.
23 PHP.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Server side basics CS382 1

URLs and web servers  Usually when you type a URL in your browser:  Your computer looks up the server's IP address using DNS  Your browser connects to that IP address and requests the given file  The web server software (e.g. Apache) grabs that file from the server's local file system  The server sends back its contents to you CS

URLs and web servers (cont.) 3 Web/Application Server Apache, Websphere SW(Java Servlets, XML Files) Database CS382

URLs and web servers (cont.)  Some URLs actually specify programs that the web server should run, and then send their output back to you as the result:  The above URL tells the server facebook.com to run the program home.php and send back its output CS

Server-Side web programming  Server-side pages are programs written using one of many web programming languages/frameworks  examples: PHP, Java/JSP, Ruby on Rails, ASP.NET, Python, Perl CS382 5

Server-Side web programming (cont.)  Also called server side scripting:  Dynamically edit, change or add any content of a Web page  Respond to user queries or data submitted from HTML forms  Access any data or databases and return the results to a browser  Customize a Web page to make it more useful for individual users  Provide security since your server code cannot be viewed from a browser 6 CS382

Server-Side web programming (cont.)  Web server:  contains software that allows it to run server side programs  sends back their output as responses to web requests  Each language/framework has its pros and cons  we use PHP CS382 7

What is PHP?  PHP stands for "PHP Hypertext Preprocessor"  Server-side scripting language  Used to make web pages dynamic:  provide different content depending on context  interface with other services: database, , etc.  authenticate users  process form information  PHP code can be embedded in XHTML code CS382 8

Lifecycle of a PHP web request 9 Hello world! User’s computer Server computer Hello.php CS382

Why PHP?  Free and open source  Compatible  as of November 2006, there were more than 19 million websites (domain names) using PHP.more than 19 million websites (domain names) using PHP  php/all/all php/all/all  Simple CS382 10

Hello World! CS <?php print "Hello, world!"; ?> PHP Hello world! output

Viewing PHP output 12 Hello world! CS382

PHP Basic Syntax 13 CS382

PHP syntax template 14  Contents of a.php file between are executed as PHP code  All other contents are output as pure HTML  We can switch back and forth between HTML and PHP "modes" HTML content <?php PHP code ?> HTML content <?php PHP code ?> HTML content... PHP CS382

Console output: print CS print "Hello, World!\n"; print "Escape \"chars\" are the SAME as in Java!\n"; print "You can have line breaks in a string."; print 'A string can use "single-quotes". It\'s cool!'; PHP Hello world! Escape "chars" are the SAME as in Java! You can have line breaks in a string. A string can use "single-quotes". It's cool! output print "text"; PHP

Variables 16 $user_name = “mundruid78"; $age = 16; $drinking_age = $age + 5; $this_class_rocks = TRUE; PHP $name = expression; PHP  names are case sensitive  names always begin with $, on both declaration and usage  always implicitly declared by assignment (type is not written)  a loosely typed language (like JavaScript or Python) CS382

Variables 17  basic types: int, float, boolean, string, array, object, NULL  test type of variable with is_type functions, e.g. is_string  gettype function returns a variable's type as a string  PHP converts between types automatically in many cases:  string → int auto-conversion on +  int → float auto-conversion on /  type-cast with (type):  $age = (int) "21"; CS382

Arithmetic operators 18  + - * / %  = += -= *= /= %=.=  many operators auto-convert types: 5 + "7" is 12 CS382

Comments 19 # single-line comment // single-line comment /* multi-line comment */ PHP  like Java, but # is also allowed  a lot of PHP code uses # comments instead of // CS382

String Type 20  zero-based indexing using bracket notation  there is no char type; each letter is itself a String  string concatenation operator is. (period), not +  5 + "2 turtle doves" === 7  5. "2 turtle doves" === "52 turtle doves"  can be specified with "" or '' $favorite_food = "Ethiopian"; print $favorite_food[2]; $favorite_food = $favorite_food. " cuisine"; print $favorite_food; PHP CS382

String Functions 21 # index $name = "Stefanie Hatcher"; $length = strlen($name); $cmp = strcmp($name, "Brian Le"); $index = strpos($name, "e"); $first = substr($name, 9, 5); $name = strtoupper($name); PHP CS382

String Functions (cont.) 22 CS382

Interpreted Strings 23 $age = 16; print "You are ". $age. " years old.\n"; print "You are $age years old.\n"; # You are 16 years old. PHP  strings inside " " are interpreted  variables that appear inside them will have their values inserted into the string  strings inside ' ' are not interpreted: CS382 print ' You are $age years old.\n ' ; # You are $age years old. \n PHP

Interpreted Strings (cont.) 24 print "Today is your $ageth birthday.\n"; # $ageth not found print "Today is your {$age}th birthday.\n"; PHP  if necessary to avoid ambiguity, can enclose variable in {} CS382

Interpreted Strings (cont.) 25 $name = “Xenia"; $name = NULL; if (isset($name)) { print "This line isn't going to be reached.\n"; } PHP  a variable is NULL if  it has not been set to any value (undefined variables)  it has been assigned the constant NULL  it has been deleted using the unset function  can test if a variable is NULL using the isset function  NULL prints as an empty string (no output) CS382

for loop (same as Java) 26 for (initialization; condition; update) { statements; } PHP CS382 for ($i = 0; $i < 10; $i++) { print "$i squared is ". $i * $i. ".\n"; } PHP

bool (Boolean) type 27 $feels_like_summer = FALSE; $php_is_great = TRUE; $student_count = 7; $nonzero = (bool) $student_count; # TRUE PHP CS382  the following values are considered to be FALSE (all others are TRUE):  0 and 0.0 (but NOT 0.00 or 0.000)  "", "0", and NULL (includes unset variables)  arrays with 0 elements  FALSE prints as an empty string (no output); TRUE prints as a 1

if/else statement 28 if (condition) { statements; } elseif (condition) { statements; } else { statements; } PHP CS382

while loop (same as Java) 29 while (condition) { statements; } PHP CS382 do { statements; } while (condition); PHP

Math operations 30 $a = 3; $b = 4; $c = sqrt(pow($a, 2) + pow($b, 2)); PHP CS382 math functions math constants

Int and Float Types 31  int for integers and float for reals  division between two int values can produce a float $a = 7 / 2; # float: 3.5 $b = (int) $a; # int: 3 $c = round($a); # float: 4.0 $d = "123"; # string: "123" $e = (int) $d; # int: 123 PHP CS382

XAMPP  Download from: windows.html windows.html  Test on a browser: type “localhost”, check if the virtual server is up.  How to run your php  PHP code will run only if you save your files in: c:/xampp/htdocs  You will see your php results by running: localhost/filename.php CS382 32

Changing xampp default directory  Go to C:\xampp\apache\conf\  Edit the httpd.conf file and replace the line DocumentRoot C:/xampp/htdocs" to your liked one.  Restart the xampp server CS382 33

PHP exercise 1  Define a variable called 'name' containing the text 'Mario' and then write "I am Mario." using the variable to write the 'Mario' part. You may only use two commands max!  Use the code from the previous example but add a check using an 'if' condition to check whether the name is ‘Mario'. Place the text from the previous example in the 'if' condition. In other words: If the name is 'mario' write 'I am mario‘  Try changing the $name variable to 'awaken'. You'll notice that the previous script writes nothing (If it doesn't, go back and redo #2, it's not complete!) In other words: If the name is 'mario', write 'I am mario' If the name isn't 'mario', write 'No, no, no. That is not my name!' CS382 34

PHP exercise 2  Use a while-loop that starts at 0 and keeps running while the number is lower then 5. Write the variable to the screen after each run. This is how it should look like on the screen when written correctly:  Modify the previous example to use a 'for' loop instead of a 'while' loop CS382 35

PHP exercise 3  Loops are very useful in creating lists and tables. In this PHP exercise, you will use a loop to create a list of equations for squares.  Using a for loop, write a script that will send to the browser a list of squares for the numbers Use the format, "1 * 1 = 1", and be sure to include code to print each formula on a different line. CS382 36

PHP exercise 4  HTML tables involve a lot of repetitive coding - a perfect place to use for loops. You can do even more if you nest the for loops.  In this PHP exercise, use two for loops, one nested inside another. Create the following multiplication table: CS

PHP exercise 5  Create two variables that store the strings: “Harry” and “Potter”  Find and add the length of the two string variables  Concatenate the two string variables  Search for the string: “otter” in the two strings  If the string “otter” is found, print: “You have an otter in your name”  Submit all exercises on: Blackboard, Assignments, PHP-Intro CS382 38

More practice  CS382 39