Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1464
  • Last Modified:

PHP session_id() every time is different after refrech page

I have problem ,PHP session_id() every time is different ,when i reload or go to other page,I need that it be same when user are login to site. Please help me? What can be. servers session configuration standartic.
Thang you.Waiting your answers
0
domka
Asked:
domka
  • 6
  • 5
  • 5
  • +2
1 Solution
 
afzzCommented:
two things

1. did you try a different browser?
     ie6/7 have a 20 cookie limit per domain. If you have over 20 cookies for the domain stored in ie, delete some and try.

2. sometimes you will need to set the following before doing a session_start() call


ini_set('session.cookie_domain','.yourdomain.com');

Alternatively you can set session.cookie_domain to '.yourdomain.com' in the php.ini file
0
 
Ali KayahanFull Stack DeveloperCommented:
Are you sure that you didnt specify id and you call session_id() before session_start()
0
 
domkaAuthor Commented:
i use ie7 , mozilla and results same.
you can look on top on site http://www.medziosandelis.lt/ms_test/  show session id . as i know it generate one time, when user browse site pages. As i undestand, session id must stay same until user close browser. But in my case,  click any link or do page refresh, session id is different .
whats can be?

session_start();
 echo session_id();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
FapikoCommented:
What version of PHP are you running? Also, check to make sure that you are using cookie based sessions. If you aren't you may have to turn on transperant sid support and set url_rewriter.tags to rewrite links for you so that it passes the session id when you navigate to a different page.
0
 
domkaAuthor Commented:
i use PHP Version 5.2.5
session.use_cookies =On
0
 
afzzCommented:
your server is not sending any cookie. You may have to check your server settings. PHP is generating the required information but your server is not sending the session cookie.

Or you can try using the setcookie funtion to set your session cookie via your script
0
 
afzzCommented:
after you call session_start();
setcookie("PHPSESSID",session_id());

Open in new window

0
 
FapikoCommented:
Can you paste the results that you find under session in a phpinfo() call?
0
 
domkaAuthor Commented:
Session Support  enabled  
Registered save handlers  files user sqlite  
Registered serializer handlers  php php_binary wddx  

Directive Local Value Master Value
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 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path C:\WINDOWS\Temp C:\WINDOWS\Temp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>session.save_path C:\WINDOWS\Temp C:\WINDOWS\Temp
is that a copy/paste error?
0
 
domkaAuthor Commented:
how cookie set diferent user. evethy one user have diferent session id ?
0
 
afzzCommented:
after you call session_start();

1:

      

setcookie("PHPSESSID",session_id());
if(!isset($_COOKIE['PHPSESSID']))
setcookie("PHPSESSID",session_id());

Open in new window

0
 
domkaAuthor Commented:
I dont know, is given server, maybe need change in script this path, because i cant change configuration.
0
 
afzzCommented:
do this on all pages where you need session support
session_start();
if(!isset($_COOKIE['PHPSESSID']))
setcookie("PHPSESSID",session_id());

Open in new window

0
 
FapikoCommented:
Yes, when the session starts it is supposed to set a cookie named PHPSESSID to the ID of the session. The session id is unique for each user. PHP saves all the session data for that session id in a file in C:\Windows\Temp.

If what afzz recommends does not work, I think the problem may be that you are outputting information to the browser before you start the session. This is not allowed because the browser sets the cookie before it even receives any of the content to be displayed.  In order to fix this make sure that session_start() occurs at the top of your script, before anything is getting output to the browser.
0
 
domkaAuthor Commented:
Thank you,Fapiko,i think you are right. i always like php sessions until this project, for me this mirackle first time :). so now i desided dont waist time, because for this project soon deadline, and created session id by self, each login user have unique session id. Everthing will be ok, but found one problem, when you use pHP session and when user  are login in site, he can close browser window (X top right coner)and often session destroy automatical. but in my case no :(.i can destroy session,.
if i can check when browser is close, after i can update database or delete log file.
is it possible to check when browser is close or closing?
0
 
FapikoCommented:
What I would do is put session_set_cookie_params(time() + 300); on each page after starting the session. That will tell the browser not to use the cookie after five minutes. By putting it on every page, as long as the user keeps browsing the site it will not kill the cookie.
0
 
FapikoCommented:
I should note that setting the cookie lifetime to 0, as your configuration has it, should tell the browser to get rid of the cookie after it closes. However, some browsers choose not to listen to this, either because they aren't operating correctly or because the user tells it not to, and save the cookie anyways. Generally if you give it a specific time to expire the browser will listen to that and get rid of the cookie when told to.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now