Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP session_id() every time is different after refrech page

Posted on 2008-06-15
18
1,456 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
LVL 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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