session and cookies ,get and post methods

19

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 16-Jul-2015

128 views

Category:

Documents


1 download

TRANSCRIPT

Sreya chandran.v

[email protected]

www.facebook.com/sreya

twitter.com/username

in.linkedin.com/in/profilename

Session, Cookies, GET and POST

Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

HTTP

HTTP is an TCP/IP based communication protocol, which is

used to deliver data (HTML files, image files, query results

etc) on the World Wide Web.

It provides a standardized way for computers to communicate

with each other.

HTTP is stateless. The server and client are aware of each

other only during a current request.

Cookies

• Cookie are small text files that website can leave on visitors

hard disk.

• Common use of cookies are:

• Remembering user name.

• Maintaining shopping cart.

• Keeping track of previously viewed content.

Creating Cookie

setcookie(“UserId” , ”1008” , ”time()+3600”);

Cookie variable Name

Cookie variable value

Expiration time

Accessing cookie

<?php

// Print a cookie

echo $_COOKIE[“UserId"];

// A way to view all cookies

print_r($_COOKIE);

?>

• The PHP $_COOKIE variable is used to retrieve a cookie

value.

Destroying cookie

• There is no special method to destroy a cookie, we can achieve

it by setting the cookie time into a past time so that it destroy

it.

setcookie(“UserId” , ”1008” , ”time()-100”);

Sessions

• A PHP session variable is used to store information about, or

change settings for a user session.

• The session values by default expire when the browser is

closed.

• Technically , session are just a form of cookies with out an

expiration date.

Session

• Session can be started in two ways in php.

• By calling the session.auto_start configuration setting in “php.in”.

• Calling session_start() on beginning of each pages whenever you

use session.

• Creating and accessing session.

• Once the session is started you can create and access session variables like any

other array variables.

$_SESSION[‘UserId']=1008;

GET and POST

• There are two methods that we can send form data from client

to server.

• GET allows you to send data as part of the query string.That

means data will be appended with the url.

• POST method transfers information via HTTP message body

The information is encoded and put into message body called

QUERY_STRING.

GET

• The PHP provides $_GET associative array to access all the

sent information using GET method.

• GET can't be used to send binary data, like images or word

documents, to the server.

http://www.test.com/index.htm?name1=value1&name2=value2

POST

• The POST method can be used to send ASCII as well as binary

data.

• The PHP provides $_POST associative array to access all the

sent information using POST method.

<form method="post" action="registration.php">

THANKYOU

Want to learn more about programming or Looking to become a good programmer?

Are you wasting time on searching so many contents online?

Do you want to learn things quickly?

Tired of spending huge amount of money to become a Software professional?

Do an online course @ baabtra.com

We put industry standards to practice. Our structured, activity based courses are so designedto make a quick, good software professional out of anybody who holds a passion for coding.

Follow us @ twitter.com/baabtra

Like us @ facebook.com/baabtra

Subscribe to us @ youtube.com/baabtra

Become a follower @ slideshare.net/BaabtraMentoringPartner

Connect to us @ in.linkedin.com/in/baabtra

Give a feedback @ massbaab.com/baabtra

Thanks in advance

www.baabtra.com | www.massbaab.com |www.baabte.com

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode

Start up VillageEranakulam,Kerala, India.

Email: [email protected]

Contact Us