Solved

PHP session_id() every time is different after refrech page

Posted on 2008-06-15
18
1,454 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

15 Experts available now in Live!

Get 1:1 Help Now