Solved

PHP session_id() every time is different after refrech page

Posted on 2008-06-15
18
1,453 Views
Last Modified: 2008-08-01
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
Comment
Question by:domka
  • 6
  • 5
  • 5
  • +2
18 Comments
 
LVL 4

Expert Comment

by:afzz
ID: 21788519
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
 
LVL 14

Expert Comment

by:ali_kayahan
ID: 21788526
Are you sure that you didnt specify id and you call session_id() before session_start()
0
 

Author Comment

by:domka
ID: 21788562
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
 
LVL 3

Expert Comment

by:Fapiko
ID: 21788569
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
 

Author Comment

by:domka
ID: 21788591
i use PHP Version 5.2.5
session.use_cookies =On
0
 
LVL 4

Expert Comment

by:afzz
ID: 21788603
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
 
LVL 4

Expert Comment

by:afzz
ID: 21788613
after you call session_start();
setcookie("PHPSESSID",session_id());

Open in new window

0
 
LVL 3

Expert Comment

by:Fapiko
ID: 21788614
Can you paste the results that you find under session in a phpinfo() call?
0
 

Author Comment

by:domka
ID: 21788622
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21788624
>session.save_path C:\WINDOWS\Temp C:\WINDOWS\Temp
is that a copy/paste error?
0
 

Author Comment

by:domka
ID: 21788631
how cookie set diferent user. evethy one user have diferent session id ?
0
 
LVL 4

Expert Comment

by:afzz
ID: 21788634
after you call session_start();

1:

      

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

setcookie("PHPSESSID",session_id());

Open in new window

0
 

Author Comment

by:domka
ID: 21788636
I dont know, is given server, maybe need change in script this path, because i cant change configuration.
0
 
LVL 4

Expert Comment

by:afzz
ID: 21788641
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
 
LVL 3

Expert Comment

by:Fapiko
ID: 21788643
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
 

Author Comment

by:domka
ID: 21788692
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
 
LVL 3

Expert Comment

by:Fapiko
ID: 21788830
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
 
LVL 3

Accepted Solution

by:
Fapiko earned 500 total points
ID: 21788841
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now