Zend Framework session problem on IE - php

I have a problem with zend session.If i don't define expire date parameter for session while using it, and i close the browser in firefox the session destroyed.However, in IE it doesn't.
Thanks in advance

There are several parameters that can be manipulated to change the behavior of the PHP session management. These parameters are set in the php.ini file in the section headed [Session].
look for:
session.cookie_lifetime
This parameter holds the life of a session cookie in seconds and is used by PHP when setting the expiry date and time of a cookie. The default value of 0 sets up a session cookie that lasts only while the browser program is running. Setting this value to a number of seconds other than 0 sets up the cookie with an expiry date and time. The expiry date and time of the cookie is set as an absolute date and time, calculated by adding the cookie_lifetime value to the current date and time on the server machine.
[ The actual expiry of the cookie is performed by the browser, which compares the expiry date and time of the cookie with the client machine's date and time. If the date and time are incorrectly set on the client, a cookie might expire immediately or persist longer than expected. ]

Related

PHP cookie returning "deleted" as value

This is a really odd issue I'm having, and I'm having a hard time figuring out what's going on. Once in awhile, my cookie returns the value "deleted" instead of its proper value. Do any web browsers turn the cookie value to "deleted" if it has expired?
I've done a ton of Google searches and SO searches, and can't find anything like this.
Has anyone seen this before?
Check to ensure that when you call setcookie() you are setting a reasonable expiry time that will ensure that your cookie will not expire while being used.
From the php documentation (trimmed for important parts):
The time the cookie expires. This is a Unix timestamp so is in number
of seconds since the epoch. In other words, you'll most likely set
this with the time() function plus the number of seconds before you
want it to expire.
If set to 0, or omitted, the cookie will expire at the end of the
session (when the browser closes).
EDIT
further down the setcookie() documentation I found this
Cookies must be deleted with the same parameters as they were set
with. If the value argument is an empty string, or FALSE, and all
other arguments match a previous call to setcookie, then the cookie
with the specified name will be deleted from the remote client. This
is internally achieved by setting value to 'deleted' and expiration
time to one year in past.
i.e. it seems that your cookie is somewhere being updated to either an empty string or being set to false.

Persistent cookie vs Temporary cookie

I am new to php , I came across cookie and persistent cookie and i understand the difference between them.My question is that how can i make cookie persistent or temporary.I found only one syntax for cookies
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
Thanks
Phisically speaking, there is only one kind of cookie. You can make it persistent by choosing a large enough expiration time. If the expiration time is set to 0, the cookie will last only until your page is opened in the browser.
Your example cookie is persistent, it expires in one hour.
Here is a link with a short explanation.
Most likely you can hardly access the phisical cookie on your hard disk, because borwsers store them in their internal logic. For example Firefox store cookies in a local SQLite database file in the browser's profile folder.
When creating a cookie, 3rd argument (time()+3600 in your example) specifies cookie's expiry date.
time()+3600 means now+3600 seconds, which is 1 hour in the future. Time() function returns current time (unix time) in seconds.
There is no such thing as a really permanent cookie, more like expiring far in the future cookie.

how to kill the session cookie after a period of time in php

if I define the session.cookie_lifetime to be zero so the cookie will only be killed after the browser is closed. but if I want to sent a max time which after that even if the browser was not closed the session will end anyway???? integer
This makes the cookie to be expired in one hour.
setcookie("TestCookie", $value, time()+3600);
More about setting cookie is at here.
Assign value for session.cookie_lifetime in PHP ini file.
session.cookie_lifetime=300 for 5 mins
Normal Cookie
From php.net
The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
That will give a nice long cookie.
Session Based Cookie
php.net link [http://www.php.net/manual/en/function.session-set-cookie-params.php]
For Session cookies use an int in seconds [360 = 6mins or 21600 = 6hours]
Also, for the session() cookie type make sure to add it before you start the session
$lifetime=600;
session_set_cookie_params($lifetime);
session_start();

Session destroy on browser close

I have heard many times that a session get destroy as our browser close.
Then how I keep logged in after closing and reopening my browser.
Please help
You keep login because your sessions are not destroyed even when the browser is closed. Sessions destroying on the closing of the browser is default behaviour but but this does not mean its the only behaviour. You can extend the expiry time of session.
This behaviour can be changed in the php.ini file by altering the line:
Keeping a session alive indefinitely
session.cookie_lifetime = 0
So just check when you have set the expiry time for the sessions. Although using cookies will be a good option
Note:- Remember to restart your web server after making this change.
You have to use Cookies.
You can use the setcookie() function and read the value with the $_COOKIE['cookiename'] variable.
Use cookies, with a predefined expire time, I like 1 year
You can use cookies. Cookies are data that is stored directly on the HDD so that even if the browser was closed, cookies still can be read if it haven't expired yet.
Here is an example of setting up a cookie.
Paste this code BEFORE the tag.
<?php setcookie("$name", "$value", $time); ?>
Where $name is the cookie name, $value is the cookie value and $time is the time when your cookie will be expired. For example $time = time()+86400; will set your cookie to expire after 1 day. The 86400 value is the number of seconds in a day, 60seconds times 60minutes times 24hours, so 60x60x24 = 86400.

PHP - Setting Cookie Expire + Time

A cookie isn't being set on my computer. It works locally but not live. I only want the cookie to exist for 20 minutes. The only reason I can think of that it won't work is because the server is in the states. I am x hours ahead. Thus the cookie set time is already expired. Is this correct?
setcookie($cookiename, $cookie, time() + 1200);
If the server time is 6am and my time is 12pm. Would the cookie be set to expire at 6:20am or 12:20pm?
If it is the former, how do I set the cookie expiry time based on the users local time? If it is the later I will do some more trouble shooting on Monday.
I've had a similar problem in the past, the advice I was always given is to make sure cookies (if set in different time zones) have an expiration of a minimum of 25 hours. This enables anyone anywhere to utilise the cookie. In alot of cases an invalid cookie = no access = a big deal.
Modern computing has made reservations for this, and synchronised time will make sure cookies are always set in the users local time. That said, exceptions are still to be found.
20 minutes is a very short time to enable a cookie, consider increasing it. If the cookie is still not set locally, I would assume your browser has blocked incoming cookies from the server.
The time() function will get the server time, but I believe Cookies use GMT time.
Easiest way to get the GM time from PHP is to use:
<?php
$gmtime = gmdate('U');
?>
So you'd set the cookie like this:
setcookie($cookiename, $cookie, gmdate('U') + 1200);

Categories