COOKIES & SESSIONS
-------------------------------------------------------------------------------------
1.what is cookie?
ans) 1->A cookie is used to oftenly identified the user.
2->A cookie is a small file that is stored on the user computer.
(client computer)
(client computer)
3->each time the same computer requests a page with a browser, it will
send the cookie.
send the cookie.
4->A cookie is stored the name and value pair.
5->a browser can accept only 20 cookies.
2) how to create the cookie?
ans) By using setcookie() function.
syntax:-setcookie(name,value,expire,path,domain)//HTTP
(or)
Setcookie (name, value, expire, path, domain, secure)//HTTPS
ex:-setcookie("apparao","raju",time()+3600);
Name:-this is cookie name
Value:-this is the value of the cookie,it stores the information
Expire:-time()+3600.
Path:-The path on the server in which the cookie will be available on.
domain:-The domain that the cookie is available.
SECURE:-cookie is transmitted only with secured HTTPS CONNECTION.
true/false, 1->means secured manner ,0->unsecured manner.
how to delete a cookie:-
setcookie(name," ",expirenegitivetime);
ex:- setcookie("apparao"," ",time()-3600).
SESSIONS
Session :-( manual)
1->A visitor accessing your web site is assigned a unique id, this so-called session id.
This is either stored in a cookie on the user side or is propagated in the URL.
session variable holds information about one single user, and available all
pages in one application
(or)
2->an internet session can be defined as interaction between a user first request for
a page from a site,untill the user leaves the site,
a )browser requests a page from the server first time.
b) the responds with the requested page and sets a cookie containing the session id.
c) the browser request additional pages from the webserver,pasing the cookie
containing the session id back to the server with each request.
(or)
3->when you are working with an application,you open it ,do some changes and when
you close the application this much like a session.
the computer knows who u r,but the internet doesn't who u r.bcoz http address doesn't
maintain the state.
maintain the state.
php session solve this problem by allowing to store user information on the server for
later use session inforamtion is temporary and will be deleted that the user has left the
website.
*for permenent storage you to store the information in the database.*
later use session inforamtion is temporary and will be deleted that the user has left the
website.
*for permenent storage you to store the information in the database.*
Methods:-
1) session_start() creates a session or resumes the current one based on the
Current session id that's being passed via a request, such as GET, POST, or
a cookie.
ex:-page1.php
page2.php
2)isset():- it is used to checks the session variable already set or not.
If it is already set it will increment the counter.
ex:-session1.php
3)unset():-it is used to free the session. ex:-session1.php
4)session_destroy():-it will destroy the session.//ex:-session3.php,session4.phpsession5.php
5)session_commit() or session_write_close();//it is used to add new data to the session.
6)session_register($string):-takes string as argument ,and register the variable
named by the string.
if it is registed it returns true other wise false
7)session_id():- It is used to get or set the session id for the current session.
8)session_encode()->returns a stirng with the contents of the current session encoded with in.
9)session_decode()->decode the session data, and stored in the session.
10)session_save_path()->current session save in that path.
11)session_unregister()->unregister the global variable name from the current session.
12)session_name([string name])->get the session name.
No comments:
Post a Comment