473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Function to identify each user?

mikek12004
200 100+
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
Expand|Select|Wrap|Line Numbers
  1. if (!isset($_SESSION["id"]))
  2. {
  3.     $_SESSION["id"]=rand(100000000,999999999);
  4. }
  5.  
and in the logout.php (the script used when entered as another user) I simply do
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. session_destroy();
  3.  
How can this be done with cookies? (since if the browser is closed sessions get lost)
a friend suggested this
Expand|Select|Wrap|Line Numbers
  1. function GetCartId()
  2. {
  3.         if(isset($_COOKIE["cartId"]))
  4.         {
  5.             return $_COOKIE["cartId"];
  6.         }
  7.         else
  8.         {
  9.             // There is no cookie set. We will set the cookie
  10.             // and return the value of the users session ID
  11.             setcookie("cartId", session_id(), time() + ((3600 * 24) * 30));
  12.             $a=session_id();
  13.  
  14.         }
  15.     return $a;    
  16.  
  17. }
  18.  
  19.  
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
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. setcookie("cartId", "", time()-3600)
  3. session_destroy();
  4.  
but still nothing why?
Sep 9 '09 #1
11 3953
Dormilich
8,658 Expert Mod 8TB
@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).
Sep 9 '09 #2
mikek12004
200 100+
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)
Sep 9 '09 #3
Dormilich
8,658 Expert Mod 8TB
what are your session cookie settings?

usually the session can handle its ids and cookies (mostly) by itself
Sep 9 '09 #4
mikek12004
200 100+
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.
Sep 9 '09 #5
Dormilich
8,658 Expert Mod 8TB
check out the session section when you’ve called phpinfo().
Sep 9 '09 #6
mikek12004
200 100+
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
Sep 9 '09 #7
Dormilich
8,658 Expert Mod 8TB
what about the session.cookie_* values?
Sep 9 '09 #8
mikek12004
200 100+
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
Sep 9 '09 #9
Dormilich
8,658 Expert Mod 8TB
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().
Sep 9 '09 #10
mikek12004
200 100+
so if I set it in the php file I am calling it will work? (using init_set()
if I am remember correctly)
Sep 9 '09 #11
Dormilich
8,658 Expert Mod 8TB
that sounds sensible.
Sep 9 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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++...
1
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...
0
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...
4
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...
4
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...
3
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...
6
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...
6
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...
6
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...
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
1
isladogs
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...
0
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...
0
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...
1
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....
0
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
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.