Boost PC performance: How more available memory can improve productivity
Sessions n cookies
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
3.
4. Sessions, Cookies, Get and
Post
Jaseena A P
jsnp65@gmail.com
www.facebook.com/Jaseena
Muhammed A P
twitter.com/username
in.linkedin.com/in/profilena
me
9539443588
5. What is a cookie?
Cookies are a mechanism for storing data in the
remote browser and thus tracking or identifying
users.
A cookie is a small file that the server embeds on the
user's computer. Each time the same computer
requests for a page with a browser, it will send the
cookie too. With PHP, you can both create and
retrieve cookie values.
6. HOW to create a cookie?
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE
the <html> tag.
setcookie(name, [value], [expire], [path], [domain],[se
cure]);
This sets a cookie named "uname" - that expires after
ten hours.
<?php setcookie("uname", $name, time()+36000); ?>
<html> <body> …
7. How to retrieve a cookie value?
To access a cookie you just refer to the cookie name as a
variable or use $_COOKIE array
Tip: Use the isset() function to find out if a cookie has been
set.
<html> <body>
<?php
if (isset($uname))
echo "Welcome " . $uname . "!<br />";
else
echo "You are not logged in!<br />"; ?>
</body> </html>
8. How to delete a cookie?
It will expire
or
Cookies must be deleted with the same parameters as
they were set with. If the value argument is an empty
string (""), and all other arguments match a previous call
to setcookie, then the cookie with the specified name will
be deleted from the remote client.
9. Using cookies
Cookies are small pieces of data that a server sends
to a browser for storage. When a browser contacts a
server, it sends along any cookies for that server
under the variable $_COOKIES. Similarly, a server can
set one or more cookies on the browser for retrieval
at a later time.
10. Using cookies
Cookies are sent with Web page headers, so any setting
of cookies must take place BEFORE the DOCTYPE line in
an HTML/PHP script.
PHP function setcookie specifies a cookie ID, a value,
and a length of time for which the cookie will be kept by
the browser.
PHP variable $_COOKIE is an associative array that
maintains the list of cookies set previously.
11. SESSIONS
Session support in PHP consists of a way to preserve
certain data across subsequent accesses. This enables us
to build more customized applications.
The session support allows us to register arbitrary
numbers of variables to be preserved across requests.
A visitor accessing our web site is assigned a unique
id, the so-called session id. This is either stored in a
cookie on the user side or is propagated in the URL.
12. How to create a session
The session_start() function is used to create
sessions.
<?php
session_start();
?>
13. How to Retrieve a Session Value
Register Session variable
session_register('var1','var2',...); // will also create a session
PS:Session variable will be created on using even if you will
not register it!
Use it
<?php
session_start();
if (!isset($_SESSION['count']))
$_SESSION['count'] = 0;
else
$_SESSION['count']++;
?>
14. How to Delete a Session Value
session_unregister(´varname´);
How to destroy a session:
session_destroy()
15. Session Variables
Effectively, session variables are cookies that remain active
only while the browser is actively interacting with the
server. When time elapses, or when we close our browser,
the session variables disappear.
16. some notes regarding session variables
A script uses session_start() to initialize and register any
session variables.
Session variables are sent with Web page headers, so any
setting of session information must take place before
the DOCTYPE tag.
PHP variable $_SESSION is an associative array that
maintains the list of session variables set previously.
PHP function isset determines whether a
specific $_SESSION field has a designated value.
PHP function unset removes a session value that was sent
previously, and session_unset() removes all session values.
17. GET&POST methods
Using the GET and POST methods , the browser
client can send data to the web server.
PHP the GET and POST methods are used to retrieve
information from forms , such as user input.
These methods are used data handling forms.
18. GET method
GET Method is less secure because information sent
from a form with the GET method is visible to every
one.
The GET Method has limits on the amount of
information to send because URL lengths are limited.
The browser appends the data to the URL.
The GET method can’t be used to send binary
data,like images or Word documents,to the server
In the GET method page and encoded information are
separated by the question mark (?) sign.
23. POST method
POST Method is Secure because information sent from
a form with the POST method is invisible to every one.
The POST Method has no limits on the amount of
information to send because URL lengths are
unlimited.
The browser doesn’t append the data to the URL.
The POST method can be used to send binary data,like
images or Word documents,to the server
29. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
30. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com