Week 9 PHP Cookies and Session Introduction to JavaScript.

Slides:



Advertisements
Similar presentations
Java Script Session1 INTRODUCTION.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Computer Science 103 Chapter 3 Introduction to JavaScript.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to scripting
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
2440: 211 Interactive Web Programming Expressions & Operators.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
Chapter 3: Data Types and Operators JavaScript - Introductory.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CHAPTER 4 Java Script อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
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.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
1 JavaScript
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
05 – Java Script (1) Informatics Department Parahyangan Catholic University.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
JavaScript. JavaScript is the programming language of HTML and the Web. Easy to learn One of the 3 languages of all developers MUST learn: 1. HTML to.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
REEM ALMOTIRI Information Technology Department Majmaah University.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
>> Introduction to JavaScript
Chapter 6 JavaScript: Introduction to Scripting
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
JavaScript Fundamentals
Introduction to Scripting
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
JavaScript an introduction.
<?php require("header.htm"); ?>
WEB PROGRAMMING JavaScript.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
JavaScript: Introduction to Scripting
CIS 136 Building Mobile Apps
Web Programming and Design
CS105 Introduction to Computer Concepts JavaScript
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Week 9 PHP Cookies and Session Introduction to JavaScript

PHP COOKIES What is a cookie: it is a file that a web server saves on a computer hard disk when a user visits a website that uses cookies. It is used to identify a user. example of its use is for remembering login details, items in shopping chart and so on. When there are different elements embedded on the web page from different domains, each domain can issue its own cookie. This is then referred to as third party cookie. The setcookie() function is used to create a cookie. It must come before the html tag.

Syntax The syntax of the set cookie function is thus setcookie (name, value, expire, path, domain, secure, httponly). The name and value parameter are required. All other parameters are optional. Name : the server uses the name parameter to access the cookie. Value: the value of the cookie. Expire: sets the expiry date of the cookie. If not set, the cookie expires when the browser closes. It is written thus, time() + number of seconds. Path: this is indicated by a forward slash, or a subdirectory. If it is a forward slash, the cookie is available over the entire domain. It is a subdirectory, it is available only in that subdirectory Domain: the internet domain of the cookie. Secure: it has the default value of false. If the value is true, the cookie can be transferred only across a secured connection. Httponly: the default is false. If the value is true, the cookie must use only the http protocol.

Creating a cookie that expires in 30 days <?php $name = 'chcsl'; $value = 'school of programming'; setcookie ($name, $value, time() , "/"); ?> cookies <?php echo $_COOKIE["$name"]; ?>

Deleting a cookie This is done by issuing the cookie again but with a date in the past. All parameters in the function apart from the expire parameter should be same with the parameters when it was first issued.

SESSION it is used to store information that is used across multiple pages. one difference between session and cookie is that for a session, the information is not stored on the users’ computer. Session variables by default, stores user information to be used across multiple pages and last until the browser is closed. To start a session, the session_start() function is used. It must come before any html tag like this session_start();.

The session starts a user key on the computer and when a session is opened on another page, it scans the computer for a user key. If there is a match, it access that session and if not, it starts a new session. To remove all session, the session_unset() function is used and to destroy all session, the session_destroy() function is used. The session_unset() and session_destroy() function can be used in the body part of the html. only the session start should come before any html.

Introduction to JavaScript JavaScript is the default scripting language in html. To apply JavaScript to a web document, the Script tag is used. In html 5, the type attribute is not required. It is written thus.. It uses the extension.js It can be written in an external sheet and saved with the.js extension then referenced using the src attribute in the script tag thus:

JavaScript has no inbuilt print function, there are different ways of displaying JavaScript Using document. write() Using alert() Using innerHTML() Using console. log()

First JavaScript Program using document.write () Welcome document.write("Hello World") document. write is has same function as echo or print in php.

Using alert () JavaScript var name = prompt("Enter your name", ""); if (name ==“mildred") { alert("Hello Instructor!!"); } else { alert ("hello student"); }

Using innerHTML () JavaScript document.getElementById("fox").innerHTML ="the fox jumps over the lazy dog"; The statement tells the browser to write “the fox jumps over the lazy dog” inside an html element with an id of “fox”.

Literals and variables Literals are fixed values in JavaScript. A variable is defined using the var keyword. Variables are used to store data. A variable can be declared first then a value assigned to it or a value can be added directly to it when it is declared. var x ; x = 1; Is same as var x = 1; Variables should be declared at the beginning of the script. Numbers can be written with or without decimal points and text (strings) can be written with either single or double quotes. Identifiers are used to name variables and they are case sensitive. Identifier names cannot start with a number and a reserved word cannot be used as a name.

comments Comments in JavaScript like any other language, is used to leave notes or explain a code. It is ignored by the browser. A single line comment is written with two forward slash like this // And a multiline comment is written thus /* your text goes here More text */

JavaScript operators Arithmetic Operators: + addition - subtraction * multiplication /division %modulo ++ increment -- decrement Assignment Operators: = assign value to variables += same as x = x+y -= same as x = x-y *= same as x= x*y /= same as x=x/y %= same as x =x%y. it returns the remainder of a division

Concatenation Operator: the plus sign + is used to join strings together. Using the plus sign on two numbers will produce the sum. Adding two strings together or adding a number and a string will produce a string. var name = “james”; var age = “15”; name + age = james15;

Comparison Operators == equal to === value and type are equal != not equal !== value or type are not equal > Greater than < less than >= greater than or equal to <= less than or equal to.

Operator precedence Order of precedence in JavaScript from highest to lowest () -> expression in parenthesis are executed first increment and decrement operators are executed before multiplication, division, modulo, addition and subtraction. */% multiplication, division and modulo have equal precedence and are executed from left to right. They have higher precedence than addition and subtraction. + - addition and subtraction have the lowest precedence.

JavaScript DATA TYPES String: text quoted with either single or double quotes Number: can be written with or without decimal point Boolean : true or false Array: a variable with more than one value Object: are name value pairs. It is written thus var name ={firstName =“mary”, lastName = “jacob”, age = 20}; JavaScript has dynamic types, which means same variable can be used as different types. For example var x; x = 1; x = “fox”;

The typeof operator is used to return the type of a variable or expression. Setting a variable to undefined empties the variable. Data type of null is an object.

Functions in JavaScript Function is used to separate a section of code that perform a particular task. It is declared with the keyword function followed by a name for the function and a pair of parenthesis that can take arguments. Functions can also be stored in variables without a name and called with the variable name. JavaScript functions can be called before they are declared. Function definitions: do not specify data types for parameters, do not perform type checking on passed arguments and do not check the number of arguments received.

Example Functions Welcome function sum(a, b){ var sum = a + b; return sum; } var x = 5; var y = 8; var answer = sum(x, y); document.getElementById(“add").innerHTML = "the sum of x and y is" +answer

Converting Celsius to Fahrenheit using Javascript Functions function toCelsius(fahrenheit) { return (5/9) * (fahrenheit-32); } document.write("100 F to oC is: "+ toCelsius(80));

Anonymous function Hello World var product = function (x, y){ return x*y ; } document.write(product (2,3));

Changing a text when a button is clicked javascript the story of the fox the dog's reaction Read function changetext(){ document.getElementById("fox").innerHTML = "the fox jumps over the lazy dog"; document.getElementById("dog").innerHTML = "the dog is still sleeping"; }