Page 1 of 1

Trouble with SESSION variables

Posted: Tue Dec 09, 2003 9:38 am
by dbudde
OK, I am having trouble getting my page2 recognize that page1 created the variable $_SESSION['logged_in'] because when I go to page1 and do login and go to page2, it never allows me to reach page2, my code automatically redirects me back to the page1 (login page) because it does not see that $_SESSION['logged_in'] exists (isset).

Below is the code that I am concerned about because it is not working how I beleive it should work. Any help would be greatly appreciated. I have programmed in PHP before, but it has been around 3 yrs now.

PAGE1

Code: Select all

<?php 
     session_start(); 
     $_SESSION['logged_in'] = "False"; 
?> 

PAGE2 

<?php
     session_start();
     if (!isset($_SESSION['logged_in'])) { 
          header("Location: http://returntopage1"); 
          /* Redirect browser */ 

          /* Make sure code below does not execute when we redirect. */ 
          exit; 
     } 
?>

Posted: Tue Dec 09, 2003 10:38 am
by twigletmac
Please bump your original topic instead of starting a new one on the same question - it makes it a lot easier to follow a thread.

Ok, have you checked what's in the $_SESSION array on page 2? For debugging, change page2 to:

Code: Select all

session_start(); 
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
Mac

Posted: Tue Dec 09, 2003 10:54 am
by microthick
In your php.ini, is your session.save_path set to a folder that actually exists?

ok, sorry about starting a new topic

Posted: Tue Dec 09, 2003 11:46 am
by dbudde
I was just trying to clean up my noobish attempt at showing my code.

I beleive the session.save_path is set to /tmp on my linux server which does exist, I will double check it. I will also double check to make sure that php is able to write to that directory. If this is supposed to be a path on the clients pc? please let me know and I will have to fix that.

twigletmac, I will try your idea as soon as I get home and let you know what I find, thanks for your help thus far.

Posted: Tue Dec 09, 2003 11:58 am
by microthick
It is the path on your server, so you probably have it correct. Hopefully it's the permissions problem.

ok, i checked that /tmp directory

Posted: Tue Dec 09, 2003 1:37 pm
by dbudde
Ok, I checked my /tmp directory and found a bunch of files starting with sess_.... which looked to be the session files, so I noticed none had been created today, so I went into my site and tried to access the pages as usual, then I rechecked the tmp directory and found a sess_.... file with todays date on it, so it appears to be able to have access to the directory and write to it.

I tried your idea twigletmac

Posted: Tue Dec 09, 2003 2:06 pm
by dbudde
Ok, I tried your idea twigletmac and this is what was returned to me on the page2.

Array
(
)

Which basically tells me that the array is empty? correct?
So, where is my problem here? Do I need to submit a copy of my php.ini?

I did something else

Posted: Tue Dec 09, 2003 2:18 pm
by dbudde
I just wanted to let you know that I tried something else. On page1 after "logged_in" is created I added the code you gave me and there it shows up in the $_SESSION array, but when I go to page2 it does not show up. I don't know if that will help any as far as debugging purposes.

Please, someone help me

Posted: Wed Dec 10, 2003 1:17 am
by dbudde
Please, someone help me

I found my problem

Posted: Wed Dec 10, 2003 2:07 am
by dbudde
If figured out what was wrong, if someone wants to tell me why this made a difference I would greatly appreciate it, but all it took to get my code working was to add "SID" to the SESSION_START().

Code: Select all

session_start(SID);
All the coding I have seen never mentions adding this in, someone want to explain to me why this made the difference please? Other than that my problem is solved thus far.

Posted: Wed Dec 10, 2003 4:47 am
by twigletmac
Could you show us the session part of your php.ini so we can compare the settings to our own (might help us pinpoint the problem).

Mac

ya, I will post my php.ini this evening

Posted: Wed Dec 10, 2003 9:00 am
by dbudde
Ya, I will post my PHP.INI later this evening, just the Session section as you requested, thanks for the reply.

here is my session section of php.ini

Posted: Wed Dec 10, 2003 1:31 pm
by dbudde
Ok, here is my php.ini SESSION section. Any of the lines with a semi-colon in front of it are included in the file, but are obviously not being used. Tell me what you think.

Code: Select all

&#1111;Session]

session.save_handler = files

session.save_path = /tmp

session.use_cookies = 1

session.use_only_cookies = 1

session.name = SID

session.auto_start = 0

session.cookie_lifetime = 0

session.cookie_path = /

session.cookie_domain =

session.serialize_handler = php

session.gc_probability = 1
session.gc_dividend    = 100

session.gc_maxlifetime = 1440

session.bug_compat_42 = 1
session.bug_compat_warn = 1

session.referer_check =

session.entropy_length = 0

session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

session.cache_limiter = nocache

session.cache_expire = 180

session.use_trans_sid = 0

url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset="