Problem with SESSION variables...

This is a discussion on Problem with SESSION variables... within the PHP Language forums, part of the PHP Programming Forums category; Hi. Im very new to php, and I have a problem here that I cant find the solution for. I ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-04-2003
ZoombyWoof
 
Posts: n/a
Default Problem with SESSION variables...

Hi. Im very new to php, and I have a problem here that I cant find the
solution for. I have problems with session variables, I want some
variables to maintain their value between different php script that is
being called. I have read the online manual, and here is an example from
it that doesnt work for me, it illustrates very well my problem.

File 1, index.php

<?php
// index.php

session_start();

echo '<br />Welcome to page #1';

$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();


// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';

// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>

File 2, page2.php

<?php
// page2.php

session_start();

echo '<br />Welcome to page #2<br />';

echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);

// You may want to use SID here, like we did in page1.php
echo '<br /><a href="index.php">page 1</a>';
?>

I get no output, except the date which shows 1970 bla bla

I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
touched the register_globals in php.ini, it's Off. What can be the problem
here ? Any help would be much appreciated, I'm stuck....

Thanx

/ZoombyWoof

Reply With Quote
  #2 (permalink)  
Old 11-04-2003
ZoombyWoof
 
Posts: n/a
Default Re: Problem with SESSION variables...

On Tue, 04 Nov 2003 15:32:14 +0000, Pedro wrote:

> ZoombyWoof wrote:
> [...]
>> I get no output, except the date which shows 1970 bla bla
>>
>> I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
>> touched the register_globals in php.ini, it's Off. What can be the problem
>> here ? Any help would be much appreciated, I'm stuck....

>
> What do you have for "session.save_path" in php.ini?
> Does the webserver have write- permissions are

rwxrwxrwxt owned by root, so that shouldnt be a problem, or ?

/ZW

Reply With Quote
  #3 (permalink)  
Old 11-04-2003
Pedro
 
Posts: n/a
Default Re: Problem with SESSION variables...

ZoombyWoof wrote:
[...]
> I get no output, except the date which shows 1970 bla bla
>
> I have apache 2.0.48, PHP 4.3.3 running on a Redhat 9.0 box. I have not
> touched the register_globals in php.ini, it's Off. What can be the problem
> here ? Any help would be much appreciated, I'm stuck....


What do you have for "session.save_path" in php.ini?
Does the webserver have write-access to that directory?

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Reply With Quote
  #4 (permalink)  
Old 11-04-2003
Jon Kraft
 
Posts: n/a
Default Re: Problem with SESSION variables...

ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:

> Hi. Im very new to php, and I have a problem here that I cant find the
> solution for. I have problems with session variables, I want some
> variables to maintain their value between different php script that is
> being called. I have read the online manual, and here is an example from
> it that doesnt work for me, it illustrates very well my problem.
>
> // Or maybe pass along the session id, if needed
> echo '<br /><a href="page2.php?' . SID . '">page 2</a>';


The above will only work if you set session.use_trans_sid in php.ini to 1.
Furthermore cookies must be accepted by your browser in order to work.

Alternatively you could use:

echo '<br /><a href="page2.php?'.session_name().'='.session_id(). '">page
2</a>';

Check the session cookie on page 2 with session_get_cookie_params() .. if
that's empty, the cookie hasn't been set.

http://uk.php.net/manual/en/function...kie-params.php

HTH;
JOn

--
Begathon, n.:
A multi-day event on public television, used to raise money so
you won't have to watch commercials.
Reply With Quote
  #5 (permalink)  
Old 11-04-2003
ZoombyWoof
 
Posts: n/a
Default Re: Problem with SESSION variables...

On Tue, 04 Nov 2003 15:35:08 +0000, Jon Kraft wrote:

> ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:
>
>> Hi. Im very new to php, and I have a problem here that I cant find the
>> solution for. I have problems with session variables, I want some
>> variables to maintain their value between different php script that is
>> being called. I have read the online manual, and here is an example from
>> it that doesnt work for me, it illustrates very well my problem.
>>
>> // Or maybe pass along the session id, if needed
>> echo '<br /><a href="page2.php?' . SID . '">page 2</a>';

>
> The above will only work if you set session.use_trans_sid in php.ini to 1.
> Furthermore cookies must be accepted by your browser in order to work.
>
> Alternatively you could use:
>
> echo '<br /><a href="page2.php?'.session_name().'='.session_id(). '">page
> 2</a>';
>
> Check the session cookie on page 2 with session_get_cookie_params() .. if
> that's empty, the cookie hasn't been set.
>
> http://uk.php.net/manual/en/function...kie-params.php
>
> HTH;
> JOn

I have tried all of what you suggested above, setting use_trans_sid to 1
didnt help. I used the link with session_name=session_id, didnt help. I
have changed session.save_path to /usr/local/apache2/sessions, apache owns
that directory, apache is the user who runs the server, but nothing goes
in that directory. I have checked the cookie_params, and it doesnt contain
anything else from what is set as default in php.ini.
I dont understand this....*HELP* :-)

Thanx

/ZW

Reply With Quote
  #6 (permalink)  
Old 11-04-2003
Jon Kraft
 
Posts: n/a
Default Re: Problem with SESSION variables...

ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:

> I have tried all of what you suggested above, setting use_trans_sid to 1
> didnt help. I used the link with session_name=session_id, didnt help. I
> have changed session.save_path to /usr/local/apache2/sessions, apache owns
> that directory, apache is the user who runs the server, but nothing goes
> in that directory. I have checked the cookie_params, and it doesnt contain
> anything else from what is set as default in php.ini.
> I dont understand this....*HELP* :-)


Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
phpinfo(). That will also tell you whether PHP was compiled with
--disable-session.

JOn

--
He only knew his iron spine held up the sky -- he didn't realize his brain
had fallen to the ground.
-- The Book of Serenity

Reply With Quote
  #7 (permalink)  
Old 11-04-2003
ZoombyWoof
 
Posts: n/a
Default Re: Problem with SESSION variables...

On Tue, 04 Nov 2003 18:15:12 +0000, Jon Kraft wrote:

> ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:
>
>> I have tried all of what you suggested above, setting use_trans_sid to 1
>> didnt help. I used the link with session_name=session_id, didnt help. I
>> have changed session.save_path to /usr/local/apache2/sessions, apache owns
>> that directory, apache is the user who runs the server, but nothing goes
>> in that directory. I have checked the cookie_params, and it doesnt contain
>> anything else from what is set as default in php.ini.
>> I dont understand this....*HELP* :-)

>
> Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
> phpinfo(). That will also tell you whether PHP was compiled with
> --disable-session.
>
> JOn

Yes, I'm editing the one PHP is using, it's /etc/php.ini, however, if you
mean that it should say --disable-session under configure command at the
top, it doesnt. Do I have to have disable-session compiled in ? Why is
this not the default, if it's necessary to get session to work...?

Thanx

/ZW

Reply With Quote
  #8 (permalink)  
Old 11-04-2003
Justin Koivisto
 
Posts: n/a
Default Re: Problem with SESSION variables...

ZoombyWoof wrote:

> On Tue, 04 Nov 2003 15:35:08 +0000, Jon Kraft wrote:
>
>
>>ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:
>>
>>
>>>Hi. Im very new to php, and I have a problem here that I cant find the
>>>solution for. I have problems with session variables, I want some
>>>variables to maintain their value between different php script that is
>>>being called. I have read the online manual, and here is an example from
>>>it that doesnt work for me, it illustrates very well my problem.
>>>
>>>// Or maybe pass along the session id, if needed
>>>echo '<br /><a href="page2.php?' . SID . '">page 2</a>';

>>
>>The above will only work if you set session.use_trans_sid in php.ini to 1.
>>Furthermore cookies must be accepted by your browser in order to work.
>>
>>Alternatively you could use:
>>
>>echo '<br /><a href="page2.php?'.session_name().'='.session_id(). '">page
>>2</a>';
>>
>>Check the session cookie on page 2 with session_get_cookie_params() .. if
>>that's empty, the cookie hasn't been set.
>>
>>http://uk.php.net/manual/en/function...kie-params.php
>>
>>HTH;
>>JOn

>
> I have tried all of what you suggested above, setting use_trans_sid to 1
> didnt help.


Did you restart the webserver after editing php.ini? That's a commonly
overlooked step...

> I used the link with session_name=session_id, didnt help. I
> have changed session.save_path to /usr/local/apache2/sessions, apache owns
> that directory, apache is the user who runs the server, but nothing goes
> in that directory. I have checked the cookie_params, and it doesnt contain
> anything else from what is set as default in php.ini.


Be sure that session.auto_start is off.

session.save_handler needs to be set to files for session.save_path to
be used.

session.use_cookies should be on if you want to use cookies. If you want
to use *only* cookies, then session.use_only_cookies should be on as well.

Make sure that session.gc_maxlifetime isn't set really low (default is
1440 seconds, or 24 minutes). Same with session.cookie_lifetime, but 0
is no exipre in this case. (Watch for session.cache_expire as well.)

--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Reply With Quote
  #9 (permalink)  
Old 11-04-2003
Justin Koivisto
 
Posts: n/a
Default Re: Problem with SESSION variables...

ZoombyWoof wrote:

> On Tue, 04 Nov 2003 18:15:12 +0000, Jon Kraft wrote:
>
>>ZoombyWoof <zoombywoofremove@thishotmail.com> wrote:
>>
>>>I have tried all of what you suggested above, setting use_trans_sid to 1
>>>didnt help. I used the link with session_name=session_id, didnt help. I
>>>have changed session.save_path to /usr/local/apache2/sessions, apache owns
>>>that directory, apache is the user who runs the server, but nothing goes
>>>in that directory. I have checked the cookie_params, and it doesnt contain
>>>anything else from what is set as default in php.ini.
>>>I dont understand this....*HELP* :-)

>>
>>Hm, strange, are you sure you are editing the php.ini PHP uses? Check with
>>phpinfo(). That will also tell you whether PHP was compiled with
>>--disable-session.

>
> Yes, I'm editing the one PHP is using, it's /etc/php.ini, however, if you
> mean that it should say --disable-session under configure command at the
> top, it doesnt. Do I have to have disable-session compiled in ? Why is
> this not the default, if it's necessary to get session to work...?


If id did say --disable-session, then sessions would be disabled and not
available on the server.

Check the under phpinfo() for "Configuration File (php.ini) Path" and be
sure that it is set to /etc/php.ini, otherwise all your edits will do
nothing. Also be sure to restart apache after editing.

--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Reply With Quote
  #10 (permalink)  
Old 11-04-2003
ZoombyWoof
 
Posts: n/a
Default Re: Problem with SESSION variables...

On Tue, 04 Nov 2003 18:27:23 +0000, Justin Koivisto wrote:

> ZoombyWoof wrote:
>

*snip*

>
> Did you restart the webserver after editing php.ini? That's a commonly
> overlooked step...

Oh yes I did.
>

*snip*
>
> Be sure that session.auto_start is off.

It is
>
> session.save_handler needs to be set to files for session.save_path to
> be used.

It is
>
> session.use_cookies should be on if you want to use cookies. If you want
> to use *only* cookies, then session.use_only_cookies should be on as well.

Cookies is on
>
> Make sure that session.gc_maxlifetime isn't set really low (default is
> 1440 seconds, or 24 minutes). Same with session.cookie_lifetime, but 0
> is no exipre in this case. (Watch for session.cache_expire as well.)

Default values

/ZW

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0