session,cookies and get and post methods

25

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

Post on 02-Jul-2015

413 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Session,cookies  and get and post methods
Page 2: Session,cookies  and get and post methods

WELCOME

Page 3: Session,cookies  and get and post methods

MIDHUN SUDHAKAR

[email protected]

[email protected]

twitter.com/midhunopusin.linkedin.com/pub/midhunsudhakar/86/a65/a9b/Phonenumber

9995586182

Session and cookies , GET and POST methods

Page 4: Session,cookies  and get and post methods

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

Page 5: Session,cookies  and get and post methods

content

•What are session and cookies•How it works•What are GET and POST methods•examples

Page 6: Session,cookies  and get and post methods

HTTP

•HTTP is a stateless protocol.

•Does not remember what happened between

two consecutive requests.

•Even two Requests made by same user are

different for HTTP.

•HTTP just processes a client REQUEST and supplies

the server RESPONSE.

Page 7: Session,cookies  and get and post methods

What is cookie ?

•Cookies are small piece of data

•Stored in the users computer.

•it stores info about you and your

preferences.

Page 8: Session,cookies  and get and post methods

For example.

Page 9: Session,cookies  and get and post methods
Page 10: Session,cookies  and get and post methods
Page 11: Session,cookies  and get and post methods

It is not limited to remember just our languages.

•It can contain time you visited a web site.

•Or items in your shopping cart

•Or even contain all the links your clicked.

Page 12: Session,cookies  and get and post methods

Syntax and example

Syn:

Setcookie(name, value, expire, path, domain);

Ex:

setcookie("user", "Alex Porter", time()+3600);

click ME

Page 13: Session,cookies  and get and post methods

To Read Cookie Values

$_COOKIE['CookieName'];

$_REQUEST['CookieName'];

To Destroy a cookie

setcookie("user", "", time()-3600);

Page 14: Session,cookies  and get and post methods

•It is same like cookies

•But it stored in the server.

•Usually used for handle user info

about one session

•Default expire time is 24mnts

What is session ?

Page 15: Session,cookies  and get and post methods

Syntax and example

Syn:

session_start();

$_SESSION[‘name']=value;

Ex:

$_SESSION[‘userid']=100;

Page 16: Session,cookies  and get and post methods

Accessing session variable

$_SESSION['views'];

Destroying a Session

unset($_SESSION[‘userid']);

session_destroy();

click Me

Page 17: Session,cookies  and get and post methods

Why GET and POST methods?

These are two ways the browser client can send

info to the web server.

Page 18: Session,cookies  and get and post methods

GET method

•It sends only limited amount of data.

•Info send using GET method will appear in

browser URL

•PHP provides $_GET associative array to access info.

Page 19: Session,cookies  and get and post methods

example

<?php

if( $_GET["name"] || $_GET["age"] ) {

echo "Welcome ". $_GET['name']. "<br />";

echo "You are ". $_GET['age']. " years old.";

}

?>

<html>

<body>

<form action="<?php $_PHP_SELF ?>" method="GET">

Name: <input type="text" name="name" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

</body>

</html> clickME

Page 20: Session,cookies  and get and post methods

POST method

• info sent by using POST method is not visible to

users.

•does not have any restriction on data size to be sent.

•PHP provides $_POST associative array to access

Page 21: Session,cookies  and get and post methods

example<?php

if( $_POST["yourname"] || $_POST["yourage"] )

{

echo "Welcome ". $_POST['yourname']. "<br />";

echo "You age is ". $_POST['yourage']. " years.";

exit();

}

?>

<html>

<body>

<form action="<?php $_PHP_SELF ?>" method="POST">

Your Name: <input type="text" name="yourname" />

Your Age: <input type="text" name="yourage" />

<input type="submit" />

</form>

</body>

</html> click ME

Page 22: Session,cookies  and get and post methods

THANK YOU

Page 23: Session,cookies  and get and post methods

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.

Page 24: Session,cookies  and get and post methods

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

Page 25: Session,cookies  and get and post methods

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