/    Sign up×
Community /Pin to ProfileBookmark

Cookie expire times

I want my cookie not to be reset when i close the browser. The way i have it right now it expires whenever i close the browser… I REALLY REALLY need a solution to this so please if someone could give me some time id REALLY appriciate it!! I dont know how to set it this way…. i want it to expire like a week after you login not very time you close the browser. Im doing this because im an iPhone developer and i have a web app that uses this but i dont want my customers to have to login every time they open the app! Theyv been complaining about it and i need to fix it.

This is my login.php file:

[code=php]<?php

/**
* login.php
*
* @version 1.0
* @copyright 2008 by ?????? for

XNova
*/

define(‘INSIDE’ , true);
define(‘INSTALL’ , false);

$InLogin = true;

$ugamela_root_path = ‘./’;
include($ugamela_root_path . ‘extension.inc’);
include

($ugamela_root_path . ‘common.’ . $phpEx);

includeLang(‘login’);

if ($_POST)

{
$login = doquery(“SELECT * FROM {{table}} WHERE

`username` = ‘” . mysql_escape_string($_POST[‘username’]) . “‘ LIMIT 1”,

“users”, true);

if ($login) {
if ($login

[‘password’] == md5($_POST[‘password’])) {
if

(isset($_POST[“rememberme”])) {

}

@include(‘config.php’);
$cookie = $login[“id”]

. “/&#37;/” . $login[“username”] . “/%/” . md5($login[“password”] . “–” . $dbsettings

[“secretword”]) . “/%/” . $rememberme;

setcookie($game_config[‘COOKIE_NAME’], $cookie, $expiretime, “/”, “”, 0);

unset($dbsettings);
if ($login

[‘urlaubs_modus’] == 1) {
$time_out =

((($login[‘urlaubs_modus_time’] + VOCATION_TIME)-time())/3600);

if (time() >= $login[‘urlaubs_modus_time’] + VOCATION_TIME ){

header(“Location:

./options.php”);
exit;

} else {

message($lang[‘vacation_mode’].floor($time_out).$lang[‘hours’], $lang[‘vacations’]);

}
} else {

header(“Location: ./overview.php”);

}
exit;
} else {

message($lang[‘Login_FailPassword’], $lang[‘Login_Error’]);

}
} else {
message($lang

[‘Login_FailUser’], $lang[‘Login_Error’]);
}

} elseif(!empty

($_COOKIE[$game_config[‘COOKIE_NAME’]])) {
$cookie = explode

(‘/%/’,$_COOKIE[$game_config[‘COOKIE_NAME’]]);
$login =

doquery(“SELECT * FROM {{table}} WHERE `username` = ‘” .

mysql_escape_string($cookie[1]) . “‘ LIMIT 1”, “users”, true);
if

($login) {
@include(‘config.php’);
if

(md5($login[“password”] . “–” . $dbsettings[“secretword”]) == $cookie[2]) {

unset($dbsettings);
header

(“Location: ./overview.php”);
exit;

}
}
}

$parse = $lang;

$query = doquery(‘SELECT username FROM {{table}} ORDER BY

register_time DESC’, ‘users’, true);
$parse[‘last_user’] = $query

[‘username’];
$query = doquery(“SELECT COUNT(DISTINCT(id))

FROM {{table}} WHERE onlinetime>” . (time()-900), ‘users’, true);

$parse[‘online_users’] = $query[0];
$parse[‘users_amount’] =

$game_config[‘users_amount’];
$parse[‘servername’] =

$game_config[‘game_name’];
$parse[‘forum_url’] = $game_config

[‘forum_url’];
$parse[‘PasswordLost’] = $lang[‘PasswordLost’];

$page = parsetemplate(gettemplate(‘login_body’), $parse);
display

($page, $lang[‘Login’]);

// —————————————————————————————————-

——-
// History version
?>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 31.2010 — Where do you set $expiretime? (If it's not being set, then 0 is being used, which means "until the browser is closed".)
Copy linkTweet thisAlerts:
@dk_zero-coolJan 31.2010 — The expires parameter needs to be the value from PHP's time or mktime function.

time()+( ((60*60)*24)*7 ) will give you 7 days before it expires.

If you want to type a date format instead (Which is properly what you are doing wrong now), you will need to use the header() function directly to set the cookie.
Copy linkTweet thisAlerts:
@4789787authorJan 31.2010 — Someone else gave me this solution

$expiretime = time()+3600*24*30; // 30 days.

But it didnt work.... Is there any reason why?

Thanks again!
×

Success!

Help @4789787 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...