setcookie() problem

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
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

setcookie() problem

Post by Calimero »

Background: Php 5, apache 1.xx ( the one most commonly used ), MySQL 4.0.18.

Problem - I looked at php.net and managed to set up a cookie.

Now, the problem was with the part of locking to a domain.
I saw two options - one to lock to domain, other to lock to a directory on that domain. I wanted the first one, but not the second option - tried and tried - but it never functioned as I wanted.

Can anyone just post how this should be done:
name = "Big Daddy"
value = $abc.$efg
expire = when browser closes (right away)
path = /I dont need this, this ... blasted thing :twisted:
domain = mysomain.com

thanks ahead.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Code: Select all

<?php
setcookie("Big Daddy", $abc.$efg, , '/', '.mysomain.com');
?>
The cookie set here will be accessible from all subdomains of mysomain.com in any directory.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

use sessions if you want it to die when the browser is closed
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, a lot of the time, PHP resorts to sticking a cookie as the SESSION variable, so if you were recommending that for avoiding extra cookies, it probably won't help: but in terms of versatality, yeah, $_SESSION is better.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

....

Post by Calimero »

Session, hmmm ?!?

I haven't used them much - did everything with 2 frames and 10 rows of JavaScript :D.


I am conserned - what I heard about them: they take up memory slots on the server machine.

So - one session how much memory it takes from my server machine ( P4 - intel (not celeron), 1mb cache, 2 GB DDR ram, 2 x 80 GB (7200) HDD, some medium graphics card, 100 mb/s network card ).

And with it - how many sessions could my machine support with running the above mentioned servers and php app's like this forum and some search engine ( not too many functions and a moderate DB )

I hope I gave enough information - and that they are clear enough.

oh yeah, and thanks for the reply.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can hold lots of sessions.. don't worry about them unless you are storing a LOT of information in the sessions.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Sorry to be this detailed - as I have never used sessions.

can you turn this (roughly) in the numbers:

lot of sessions,

and this especialy - lots of data ( in terms of number of variables or length of variables )

Can't create a picture in my head entirely.

Thanks in advance.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

shiznatix wrote:use sessions if you want it to die when the browser is closed
Cookies can "die" when the browser is closed also.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there is no reason to quantify the sizes involved.. you have FAR more space than most servers have for storing your session data.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

plus sessions are easier to deal (atleast i think) since its just another array that you can easily deal with.
Sami wrote: Cookies can "die" when the browser is closed also.
how is this done? i thought they only deleted themselves when a cetain time expired?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

supply an expire time of zero. It's called a session cookie.
Post Reply