$_Session variables

Alles, was PHP betrifft, kann hier besprochen werden.

$_Session variables

Postby picard48 » 30. November 2010 02:45

Hello,
I think a lot has been said on this, sadly in German and frankly my German is as good as my Latin, so sorry if this is repetitive but I'm going crazy and don't know what else to do.

I'm trying a very simple script, just want to send some variables from one web page to another, an therefore wanted to use $_Session

first page:

<?php
session_start();
$_session[userlevel]=1;
echo "user: ".$_session[userlevel]."<p>";
print_r($_session);
?>

Works fine, result is:
user: 1

Array ( [userlevel] => 1 )

Second page:
<?php
session_start();
echo "user: ".$_session[userlevel]."<p>";
print_r($_session);
?>
$_Session is not being passed, result is only:
user:

Just for the fun of it, I uploaded this two pages up to a Unix server that I use and in the main server everything works fine, so I know that the scripts are doing their job, my problem is that I do all developing in my PC before I upload and I would much rather have it working on both machines, so maintaining it is simpler.

I've checked my PHP.ini file, on my PC, register_globals is on, session.save_path is to a real directory the only thing that I've seen is that the file that is created in the session.save_path is empty, no info is being stored.

Last year I was doing some $_Session variable stuff with XAMPP installed on a 32bit computer with no problem whatsoever, know I'm working on a 64bit machine with windows 7, could this be the problem? PLEASE, HELP, although I think I could work around this and use something else in order to store my data, $_Session is a much simpler way.

Thank you in advance for any advice or tip on how to fix my dilemma.
picard48
 
Posts: 4
Joined: 30. November 2010 02:18

Re: $_Session variables

Postby Altrea » 30. November 2010 04:55

picard48 wrote:I'm trying a very simple script, just want to send some variables from one web page to another, an therefore wanted to use $_Session

There is no superglobal Array $_session or $_Session.
These superglobal Arrays are case sensitive and named completely in capital letters.

picard48 wrote:I've checked my PHP.ini file, on my PC, register_globals is on

Oh no. Please don't do that. register_globals is evil evil evil!
There is NO reason to use that. Just write clean code (and use error_reporting(E_ALL|E_STRICT); at the beginning of all your script to force yourself to write cleaner code)
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6685
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: $_Session variables

Postby picard48 » 30. November 2010 14:32

And of course you are right, forgot about the capital usage yet after changing all of my _session and _Session to _SESSION still not working, any ideas?
picard48
 
Posts: 4
Joined: 30. November 2010 02:18

Re: $_Session variables

Postby Altrea » 30. November 2010 14:53

Do you have Cookies enabled to transfer the Session-ID?
or do you add the SID in your URL?

What does phpinfo() tells about your Session configuration parameters?
Do you add methods for script debugging (print_r your SESSION superglobal variable, add error_reporting(E_ALL|E_STRICT) at the beginning of your script)?
Can you post your script with your changes again?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6685
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: $_Session variables

Postby picard48 » 30. November 2010 15:19

Thank you for your time AGAIN.... Altrea

Everything goes past well except for the Notice: Use of undefined constant ul - assumed 'ul when I use the $_SESSION[ul]=1;

The one thing I've noticed is that in my tmp folder every time I use the start_session(); a new file appears I read a little into my php.ini file and under the [Session] section it says something about "Windows users have to change this
; variable in order to use PHP's session functions" and that the path has to be changed I tried changing the path to point to a different dir and using a 1 for the level of subdirs session.save_path="1;C:\xampp\sess" and now I get a lot of errors like:
Warning: session_start() [function.session-start]: open(C:\xampp\sess\1\sess_1t1r8f4lnkvcsvfc6u18im7514, O_RDWR) failed: No such file or directory (2) in C:\xampp\htdocs\tstpass\work.php on line 3

where my line 3 is only the session_start();
picard48
 
Posts: 4
Joined: 30. November 2010 02:18

Re: $_Session variables

Postby Altrea » 30. November 2010 15:51

picard48 wrote:Everything goes past well except for the Notice: Use of undefined constant ul - assumed 'ul when I use the $_SESSION[ul]=1;


You have to put Array keys in (single-)quotes. Try this:
Code: Select all
$_SESSION['ul']=1;


picard48 wrote:open(C:\xampp\sess\1\sess_1t1r8f4lnkvcsvfc6u18im7514, O_RDWR) failed: No such file or directory

The message should already be clear.
XAMPP is already well configured to use Sessions. So please undo your changes in the Session configuration unless you know exactly what you are doing.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6685
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64

Re: $_Session variables

Postby picard48 » 30. November 2010 19:10

THANK YOU!!!!
Apart from the little quirks something was wrong I guess I just uninstalled the whole xampp and re installed it and now it's working... THANK you again for all your help.
picard48
 
Posts: 4
Joined: 30. November 2010 02:18

Re: $_Session variables

Postby Altrea » 30. November 2010 19:47

You're welcome :D
Have fun with xampp and all the stuff
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 6685
Joined: 17. August 2009 13:05
XAMPP Version: 5.5.19
Operating System: W7Ux64


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests