In my page I want each user to get a unique id (which stays even if they go to another page and then come back) except when they click named "enter as other user". right now in the beginning of my page I use -
if (!isset($_SESSION["id"]))
-
{
-
$_SESSION["id"]=rand(100000000,999999999);
-
}
-
and in the logout.php (the script used when entered as another user) I simply do -
session_start();
-
session_destroy();
-
How can this be done with cookies? (since if the browser is closed sessions get lost)
a friend suggested this -
function GetCartId()
-
{
-
if(isset($_COOKIE["cartId"]))
-
{
-
return $_COOKIE["cartId"];
-
}
-
else
-
{
-
// There is no cookie set. We will set the cookie
-
// and return the value of the users session ID
-
setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
-
$a=session_id();
-
-
}
-
return $a;
-
-
}
-
-
but with the same logout.php as above doesn't work (I always get the same return) any ideas?
PS with the above solution tried in the logout.php this -
session_start();
-
setcookie("cartId", "", time()-3600)
-
session_destroy();
-
but still nothing why?
11 3953 @mikek12004
er, no. that’s what sessions are for. if you close the browser, the session is only lost, if no session cookie is set (aka the session id is lost), which is set in php.ini. the session will continue until the session lifetime is over (but data can only be accessed using the correct session id).
hmmm...kinda lost you the thing I saw was that with the first way (only sessions) the id changed whenever I closed-reopend the browser so I saw that the session variables disappears (something that I do not want to happen) so a friend suggested the GetCartId in which truly the $a returned by this fuctions stays the same but even when I destroy the session and even unset the coockie (check the 2nd half of my prev post)
what are your session cookie settings?
usually the session can handle its ids and cookies (mostly) by itself
how do I see them? I just put a clean installation of the latest xampp (just formatted the PC) so I believe all the settings must be OK.
check out the session section when you’ve called phpinfo().
Session Support :enabled
Registered save handlers : files user sqlite
Registered serializer handlers: php php_binary wddx
At the format
(Directive) (Local Value) (Master Value)
I get
session.auto_start,Off,Off
session.bug_compat_42,On,On
session.bug_compat_warn,On,On
session.cache_expire,180,180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path D:\xampp\tmp D:\xampp\tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0
what about the session.cookie_* values?
In the format
(Directive) (Local Value) (Master Value)
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
you need to set session.cookie_lifetime explicitly to make the session cookie persistent.
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params().
so if I set it in the php file I am calling it will work? (using init_set()
if I am remember correctly)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: publictom |
last post by:
I just happened to read item 47, "Control Flow", in Exceptional C++ by
Herb Sutter (which is based on Guru of the Week 12), just after reading
item 33, "Use Inlining Judiciously", in Effective C++...
|
by: keith.walter |
last post by:
My first asp.net app is almost "done" and I am stuck. Here is my
situation: I have a "mother" page add_customer.aspx and a"child" user
control add_group.ascx. On the mother page is an "add...
|
by: Mark |
last post by:
Hi - I'm using ASP.Net 1.1 with VS.Net 2003.
I have a file upload/download web app - it uploads great, but my
download function doesn't work for SWF files. If I type the complete
path to them...
|
by: Goh |
last post by:
Hi,
I would like to know how can we implement a web page that
intelligent enough to unique identify that pc have been visit before without
any cookies and login user require.
I have try...
|
by: Saber |
last post by:
When users come to website, I want to identify them (browser, referrer,
....).
I am doing it in global.asax, well, when they type www . sitename . com
the global.asax identify them and redirect...
|
by: Michel |
last post by:
Hi, I wrote an app in .Net and I whant only 1 instance of this app open for
the user; the user open my app, do some works and try to open another
instance of my app, I whant to show a message to...
|
by: Pieter |
last post by:
Hi,
For some procedures that throws exceptions, I would like to show different
messages to the user depending on what type of exception he's getting. For
instance this one: when the file is...
|
by: noel.hunt |
last post by:
I have a base class, PadRcv, with virtual functions. User code
will derive from this class and possibly supply it's own functions
to override the base class virtual functions. How can I test that...
|
by: DMUM via AccessMonster.com |
last post by:
Hello
I am trying to pass the name of my subform to a function/sub but I can't
seem to get it to work. I am using an autokey function (ctrl E) to unlock
text boxes on a subform. I have a few...
|
by: srinithi |
last post by:
1.write a program to identify whether a character entered by a user is a vowel or a consonant?
2.write a program to identify whether the number entered by user is even or odd?
3.write a program to...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |