php session doesn't work

General discussions related to php

Moderators: macek, egami, gesf

spotty
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jun 26, 2003 2:16 am

php session doesn't work

Postby spotty » Thu Jun 26, 2003 2:24 am

Hello,
my script doesn*t work:
<?php
@session_start();
session_register('userName', 'userPermissions');
$userName = 'hallo';
$userPermissions = 'no';
?>

In /tmp there is a file named sess_414cb8736b0ccc9034d0454c66eb38bb, but it's empty.
I use php-Version 4.2.2 with Linux-Kernel 2.4.20

any idea?

spotty

Flood
New php-forum User
New php-forum User
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am

Postby Flood » Thu Jun 26, 2003 3:37 am

Hi!

Perhaps it will not change anything, but if I were you, I would use $_SESSION instead of session_register...

Otherwise and in any case, define your variables before calling session_register...

/Flood

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Re: php session doesn't work

Postby Redcircle » Thu Jun 26, 2003 3:04 pm

spotty wrote:Hello,
<?php
@session_start();
session_register('userName', 'userPermissions');
$userName = 'hallo';
$userPermissions = 'no';
?>



Usin this method you need to define the variables before you register them i.e.

Code: Select all

<?php
@session_start();
$userName        = 'hallo';
$userPermissions = 'no';
session_register('userName', 'userPermissions');
?>


As flood suggests using $_SESSION is not only easier to understand but there is less code. less code means less typing. less typing means less chance for typo's means less trouble debugging.

spotty
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jun 26, 2003 2:16 am

Postby spotty » Thu Jun 26, 2003 11:13 pm

Hello,
thanks:
This doesn't work: (first defining variables and then register)

<?php
@session_start();
$userName = 'hallo';
$userPermissions = 'no';
session_register('userName', 'userPermissions');
?>

But this works:
<?php
@session_start();
$_SESSION['userName'] = 'hallo';
$_SESSION['userPermissions'] = 'no';
?>

Spotty


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest