session in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

session in php

Post by pelegk2 »

how execlly is a session defined in php?
what i mean is : when i first access a php where i activate the session
and say after 2 minutes i close the browser and open a new one then it means that a new session is being created?
how execlly all of this thing work?
and what does it mean if i open aa chile window with window.open()
which session will it get?
thnaks i nadvance
peleg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sessions are a concept whereby the browser gets a unique identifier attached to it, either through URLs or through a cookie. When using a cookie, the expiration time for it is set to 0, or when the browser closes it's window. When using the url, if you don't return with the exactly correct id on the url you will get a new one. Some implementations will give you a new one based on several more criteria as well.

As for opening a child window, if done through url's, the session id quite possibly will be lost. This depends on the implementation however. With cookies, you will continue to be in the same session.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

so ectually what your saying is that a cookie is coocike for a browser?
and if i open 2 browsers with the same url i will have 1 cookie or 2?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

1 cookie. Cookies are global in most browsers. i.e. They are shared across all instances of that particular browser. So IE and Firefox won't share the same session, but 2 windows of Firefox will share a session.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

if so i dont understand what makes the browser save my cookie and nows its me?by the ip?
by a certain uniqe browser value or what?
and how execlly the server knows i have closed the vroswer - beacuse i can close it wighougt the server knows that it happens to restart the pc and get new ip for example
and in the same time some 1 else will get my ip for example and the server will think its me?????what make me unique that he knows its oly me and no one else?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the server generally doesn't care what ip you have. it generates the id on it's own using whatever unique id system implemented by the session manager you have. don't worry about that unless you are building your complete own session manager. Generally the id has nothing to do with your ip or agent string. It'll often hinge off the time, among some other things to make sure you get an entirely unique (for a good long time at least) value.

The browser gets a cookie with your domain, the session cookie name and value (the session id, usually). The server merely looks at the cookies sent in by your browser. If the session cookie isn't present, or is invalid, it creates a new id.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

so actually what u say

Post by pelegk2 »

is that the session id is stored in my browser ram and sent to the server
and like that th server know's who i am?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes.
Post Reply