Adding Session Support

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Adding Session Support

Post by Zeceer »

Hi,

I can't get sessions to work on my system. I don't really know what to cahnge in the PHP.ini file, or what else I will have to do.

Code: Select all

їSession]
; Handler used to store/retrieve data.
session.save_handler = files

; Argument passed to save_handler.  In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this 
; variable in order to use PHP's session functions.
session.save_path = C:\PHP\sessiondata    ; argument passed to save_handler

; Whether to use cookies.
session.use_cookies = 1


; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = /

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data.  php is the standard serializer of PHP.
session.serialize_handler = php

; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_probability = 1

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public} to determine HTTP caching aspects.
session.cache_limiter = nocache

; Document expires after n minutes.
session.cache_expire = 180

; use transient sid support if enabled by compiling with --enable-trans-sid.
session.use_trans_sid = 1

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
I'm running IIS on Win 2k if thats any help
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try
session.save_path = C:/PHP/sessiondata
and make sure the IIS-account has write permissions on that directory
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Have do I change that?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

session.save_path is a parameter in your php.ini (most likely in c:\winnt)

( did I get the point? )
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Re: Adding Session Support

Post by Takuma »

Zeceer wrote:I'm running IIS on Win 2k if thats any help
If you're using IIS why do you need to use Apache?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

where did he mention apache?
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Well, the save patch is set to the directory where it saves cookies, but i can't make it work. The PHP.ini i posted in the first post is the settings i have now. Thing is i don't know what to change?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

  • open the file with a text-editor (i.e. notepad.exe)
  • change the line
    session.save_path = C:\PHP\sessiondata ; argument passed to save_handler
    to
    session.save_path = C:/PHP/sessiondata
  • save the file
  • restart IIS
if you do not have the permission to perform one of the steps ask your administrator to do so.
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

Still doesn't work 8O . I just have to live without session support then :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do you get an error message or what makes you think sessions don't work?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Sorry I got confused with httpd.conf and php.ini :oops:
This is what I have and session works.

Code: Select all

їSession]
; Handler used to store/retrieve data.
session.save_handler = user

; Argument passed to save_handler.  In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this 
; variable in order to use PHP's session functions.
session.save_path = "C:\Apache\tmp"

; Whether to use cookies.
session.use_cookies = 1

; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1

; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = /

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data.  php is the standard serializer of PHP.
session.serialize_handler = php

; Percentual probability that the 'garbage collection' process is started
; on every session initialization.
session.gc_probability = 1

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public} to determine HTTP caching aspects.
session.cache_limiter = nocache

; Document expires after n minutes.
session.cache_expire = 180

; use transient sid support if enabled by compiling with --enable-trans-sid.
session.use_trans_sid = 1

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

I've found out that it is the Session.savepatch that is wrong. But it stands on the right directory for all I know. Is there anyone that have IIS here with session support? That may check if anything is wrong?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you made sure that everybody can write to the folder that is supposed to contain the session stuff. We've currently got IIS 4.0 running on Win2K and the sessions worked fine once the permissions had been set correctly.

But to repeat what's already been said:
volka wrote:Do you get an error message or what makes you think sessions don't work?
It'll make it easier for us to help you if you tell us a bit more about what's going wrong...

Mac
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post by Zeceer »

I've made a little sessin test.

The file that sets the session:

Code: Select all

<?php
session_start();
$user = "Zeceer";

if (session_register("user"))
   &#123;
           print("User set to $user");
   &#125;
else
   &#123;
           print("Could not set the session variable");
   &#125;
?>
The file that i going to read the variable stored:

Code: Select all

<?php
session_start();
echo("Welcome, $user");
?>
This is the error I get:

Code: Select all

Notice: Undefined variable: user in D:\test2.php on line 3
Welcome,
The session is not stored.

I don't know have to set the permission to c:\php\sessiondata. Can someone please tell me have to set permissons in IIS?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try this:

Code: Select all

<?php 
session_start(); 

$_SESSION&#1111;'user'] = 'Zeceer';
echo 'User is: '.$_SESSION&#1111;'user'];
?>
and

Code: Select all

<?php 
session_start(); 
echo 'Welcome, '.$_SESSION&#1111;'user']; 
?>
Does this work?

Mac
Post Reply