session not passing variable 
Author Message
 session not passing variable

Be grateful if someone could look through this intentded to go on a server
running php 4.06. (It works on later versions)

The session seems to work OK (seesion id is the same after a refresh.) and
it sets the variable "set" but it doesn't keep it on refresh therefore my
counter is set every-time the page is refreshed rather than per visit.

session_start();
echo session_id()." <br>"; // echo seesion id as a check

echo $HTTP_SESSION_VARS['set']." <br>";

if(file_exists("counter.dat")){
   $file = fopen("counter.dat", "r");
   $new_count = fgets($file, 255);
   fclose($file);
      if (!isset($HTTP_SESSION_VARS['count'])){
         $HTTP_SESSION_VARS['set'] = 1;
         echo $HTTP_SESSION_VARS['set']. " // make sure that it is set
         $new_count++;
         $counter = fopen("counter.dat", "w");
         fputs($counter, $new_count);
         fclose($counter);
      }

Quote:
} else {

   $make_file = fopen("counter.dat", "w");
   fputs($make_file, "1");
   fclose($make_file);

Quote:
}

Many thanks
Chris


Mon, 12 Sep 2005 16:25:50 GMT  
 session not passing variable

Quote:

> The session seems to work OK (seesion id is the same after a refresh.) and
> it sets the variable "set" but it doesn't keep it on refresh therefore my
> counter is set every-time the page is refreshed rather than per visit.

> session_start();
> echo session_id()." <br>"; // echo seesion id as a check

> echo $HTTP_SESSION_VARS['set']." <br>";

> if(file_exists("counter.dat")){
>    $file = fopen("counter.dat", "r");
>    $new_count = fgets($file, 255);
>    fclose($file);
>       if (!isset($HTTP_SESSION_VARS['count'])){
>          $HTTP_SESSION_VARS['set'] = 1;
>          echo $HTTP_SESSION_VARS['set']. " // make sure that it is set
>          $new_count++;
>          $counter = fopen("counter.dat", "w");
>          fputs($counter, $new_count);
>          fclose($counter);
>       }
> } else {
>    $make_file = fopen("counter.dat", "w");
>    fputs($make_file, "1");
>    fclose($make_file);
> }

Hi Chris,
$HTTP_SESSION_VARS['set'] is set to 1 everytime because
$HTTP_SESSION_VARS['count'] is never set.

Hope this helps;
JOn



Mon, 12 Sep 2005 19:14:34 GMT  
 session not passing variable

--
Chris Skidmore

Pegasus Designs
++49 (0) 551 703478
www.pegasusdesigns.com


Quote:

> > The session seems to work OK (seesion id is the same after a refresh.)
and
> > it sets the variable "set" but it doesn't keep it on refresh therefore
my
> > counter is set every-time the page is refreshed rather than per visit.

> > session_start();
> > echo session_id()." <br>"; // echo seesion id as a check

> > echo $HTTP_SESSION_VARS['set']." <br>";

> > if(file_exists("counter.dat")){
> >    $file = fopen("counter.dat", "r");
> >    $new_count = fgets($file, 255);
> >    fclose($file);
> >       if (!isset($HTTP_SESSION_VARS['count'])){
> >          $HTTP_SESSION_VARS['set'] = 1;
> >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is set
> >          $new_count++;
> >          $counter = fopen("counter.dat", "w");
> >          fputs($counter, $new_count);
> >          fclose($counter);
> >       }
> > } else {
> >    $make_file = fopen("counter.dat", "w");
> >    fputs($make_file, "1");
> >    fclose($make_file);
> > }

> Hi Chris,
> $HTTP_SESSION_VARS['set'] is set to 1 everytime because
> $HTTP_SESSION_VARS['count'] is never set.

> Hope this helps;
> JOn

Many thanks Jon but afraid not!!! I did call the variable "count".  I
changed it to "set" in the hope it would be more readable.I missed changing
that one. This code does work on versions of php later than 4.2.3
I hope a corrected version below

if(file_exists("counter.dat")){

- Show quoted text -

Quote:
> >    $file = fopen("counter.dat", "r");
> >    $new_count = fgets($file, 255);
> >    fclose($file);
> >       if (!isset($HTTP_SESSION_VARS['set'])){
> >          $HTTP_SESSION_VARS['set'] = 1;
> >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is set
> >          $new_count++;
> >          $counter = fopen("counter.dat", "w");
> >          fputs($counter, $new_count);
> >          fclose($counter);
> >       }
> > } else {
> >    $make_file = fopen("counter.dat", "w");
> >    fputs($make_file, "1");
> >    fclose($make_file);
> > }



Mon, 12 Sep 2005 21:59:54 GMT  
 session not passing variable

Quote:



> > >       if (!isset($HTTP_SESSION_VARS['count'])){
> > >          $HTTP_SESSION_VARS['set'] = 1;

> > $HTTP_SESSION_VARS['set'] is set to 1 everytime because
> > $HTTP_SESSION_VARS['count'] is never set.

> Many thanks Jon but afraid not!!! I did call the variable "count".  I
> changed it to "set" in the hope it would be more readable.I missed
changing
> that one. This code does work on versions of php later than 4.2.3
> I hope a corrected version below

> if(file_exists("counter.dat")){
> > >    $file = fopen("counter.dat", "r");
> > >    $new_count = fgets($file, 255);
> > >    fclose($file);
> > >       if (!isset($HTTP_SESSION_VARS['set'])){
> > >          $HTTP_SESSION_VARS['set'] = 1;
> > >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is set

Hi Chris,

Ah yes, I remember you posting v4.0.6 ... there you have to register the
session variable, so:

    if (!session_is_registered("set")){
        session_register("set");
        $HTTP_SESSION_VARS['set'] = 1;
        // ...

Hope this helps;
JOn



Mon, 12 Sep 2005 22:03:21 GMT  
 session not passing variable

Quote:



> > > >       if (!isset($HTTP_SESSION_VARS['count'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;

> > > $HTTP_SESSION_VARS['set'] is set to 1 everytime because
> > > $HTTP_SESSION_VARS['count'] is never set.

> > Many thanks Jon but afraid not!!! I did call the variable "count".  I
> > changed it to "set" in the hope it would be more readable.I missed
> changing
> > that one. This code does work on versions of php later than 4.2.3
> > I hope a corrected version below

> > if(file_exists("counter.dat")){
> > > >    $file = fopen("counter.dat", "r");
> > > >    $new_count = fgets($file, 255);
> > > >    fclose($file);
> > > >       if (!isset($HTTP_SESSION_VARS['set'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;
> > > >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is
set

> Hi Chris,

> Ah yes, I remember you posting v4.0.6 ... there you have to register the
> session variable, so:

>     if (!session_is_registered("set")){
>         session_register("set");
>         $HTTP_SESSION_VARS['set'] = 1;
>         // ...

> Hope this helps;
> JOn

This looks like it could be it - I only started php after 4.1 so it came as
a shock when I needed $HTTP_[GET, POST, SESSION]_VARS ect
we live and learn

Many thanks - Chris



Tue, 13 Sep 2005 01:31:54 GMT  
 session not passing variable

Quote:



> > > >       if (!isset($HTTP_SESSION_VARS['count'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;

> > > $HTTP_SESSION_VARS['set'] is set to 1 everytime because
> > > $HTTP_SESSION_VARS['count'] is never set.

> > Many thanks Jon but afraid not!!! I did call the variable "count".  I
> > changed it to "set" in the hope it would be more readable.I missed
> changing
> > that one. This code does work on versions of php later than 4.2.3
> > I hope a corrected version below

> > if(file_exists("counter.dat")){
> > > >    $file = fopen("counter.dat", "r");
> > > >    $new_count = fgets($file, 255);
> > > >    fclose($file);
> > > >       if (!isset($HTTP_SESSION_VARS['set'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;
> > > >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is
set

> Hi Chris,

> Ah yes, I remember you posting v4.0.6 ... there you have to register the
> session variable, so:

>     if (!session_is_registered("set")){
>         session_register("set");
>         $HTTP_SESSION_VARS['set'] = 1;
>         // ...

> Hope this helps;
> JOn

This looks like it could be it - I'll check this in the morning - I only
started php after 4.1 so it came as
a shock when I needed $HTTP_[GET, POST, SESSION]_VARS ect
we live and learn

Many thanks - Chris



Tue, 13 Sep 2005 07:53:34 GMT  
 session not passing variable

Quote:



> > > >       if (!isset($HTTP_SESSION_VARS['count'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;

> > > $HTTP_SESSION_VARS['set'] is set to 1 everytime because
> > > $HTTP_SESSION_VARS['count'] is never set.

> > Many thanks Jon but afraid not!!! I did call the variable "count".  I
> > changed it to "set" in the hope it would be more readable.I missed
> changing
> > that one. This code does work on versions of php later than 4.2.3
> > I hope a corrected version below

> > if(file_exists("counter.dat")){
> > > >    $file = fopen("counter.dat", "r");
> > > >    $new_count = fgets($file, 255);
> > > >    fclose($file);
> > > >       if (!isset($HTTP_SESSION_VARS['set'])){
> > > >          $HTTP_SESSION_VARS['set'] = 1;
> > > >          echo $HTTP_SESSION_VARS['set']. " // make sure that it is
set

> Hi Chris,

> Ah yes, I remember you posting v4.0.6 ... there you have to register the
> session variable, so:

>     if (!session_is_registered("set")){
>         session_register("set");
>         $HTTP_SESSION_VARS['set'] = 1;
>         // ...

> Hope this helps;
> JOn

This looks like it could be it - I'll check this in the morning - I only
started php after 4.1 so it came as
a shock when I needed $HTTP_[GET, POST, SESSION]_VARS ect
we live and learn

Many thanks - Chris



Tue, 13 Sep 2005 07:53:44 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. openMP: threadprivate not effected and function variables not passed

2. Passing Session variables to next page

3. How to pass a session variable back to the same page

4. Passing classes with session variables

5. Session Variables not displaying.

6. session variable not available

7. php variables not passing through

8. db variables not being passed

9. config xitami/php: variables not passed

10. GET variable not being passed?

11. Variable not passing in HTML form to PHP sendmail script

12. trouble with iis not passing variables

 

 
Powered by phpBB® Forum Software