Computing.Net > Forums > Web Development > PHP sessions not working

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP sessions not working

Reply to Message Icon

Name: vevense
Date: June 16, 2004 at 13:07:46 Pacific
OS: Windows XP
CPU/Ram: AMD Athlon XP1800/512
Comment:

Hello!
We have made a site with loggin using $_SESSION for setting session variables. This works perfectly in the Windows environment (WinXP-Apache-PHP-MySQL). We now try to transfer the system to Linux. The problem is that the session variables is not set when "going to the next page" and then we get our own alert "You are not logged in".
Everything works well with MySQL, but the session variables in PHP seems not to be set.

Sample code page 1:
session_start()
some code
login-form
$_SESSION['id'];
$_SESSION['name'];
etc

Page 2
session_start()
if(!isset($_SESSION['id'] && !isset['name'])
JS-alert(You are not logged in)
else
the code for what we want to do


Please help



Sponsored Link
Ads by Google

Response Number 1
Name: anonproxy
Date: June 16, 2004 at 13:44:38 Pacific
Reply:

"
if(!isset($_SESSION['id'] && !isset['name'])
"

Globals are turned off on the Linux machine (the register_globals php.ini directive). !isset['name'] refers to a variable which doesn't exist in global scope. It exists in the array $_SESSION.


0

Response Number 2
Name: vevense
Date: June 17, 2004 at 03:17:43 Pacific
Reply:

Hello again

Thank You for Your answer

Does this mean that I can't use session variables?
Any suggestions how I can code the persistent login on the linuxbox?

(Maybe this is a stupid question, but I am quite new to php. I would appreciate any help.)

Regards


0

Response Number 3
Name: Khalid
Date: June 17, 2004 at 13:34:30 Pacific
Reply:

Anonproxy means that you should try this line:

if(!isset($_SESSION['id'] && !isset($_SESSION['name']))

Or even try it more simple to check if sessions do come through with a simple echo:

echo $_SESSION['name'];

If the above line outputs a name, then you are sure sessions do work on your new serverconfig.


0

Response Number 4
Name: vevense
Date: June 18, 2004 at 01:25:17 Pacific
Reply:

Hello again!

I have tried both if(!isset($_SESSION['id'] && !isset($_SESSION['name'])) and echo $_SESSION['name'];.
The echo outputs nothing.

How can I solve the login problem?

This is how I want it:
A login page which checks pw against MySQL.
The subsequent pages must check if the user is logged in. If not he will be returned to the login page.

Please help

Regards and thanks to all helpful people out there


0

Response Number 5
Name: anonproxy
Date: June 18, 2004 at 11:52:58 Pacific
Reply:

There are a few possibilities.

1) This is a version of PHP under 4.1 (unlikely).

2) The sessions between the two pages are different. (compare the $SID variables, make sure the cookie or URL passing is working, etc. - you are passing the session ID right?)

When things seem to make no sense, I usually start with some sample code from documentation or a tutorial. I then slowly convert it to my needs until I find the problem.


0

Related Posts

See More



Response Number 6
Name: vevense
Date: June 18, 2004 at 13:00:37 Pacific
Reply:

Jippppppppppppiiiiiiiiii!!!!!!!!!!!!!!!!!!

I found the solution myself

The problem was that I put the html and php files under my home directory without giving the web-directory the appropriate permissions.
So I did a chmod on the directory and files and then everything was OK

Have a nice weekend!


0

Response Number 7
Name: yisraelharris
Date: June 23, 2004 at 04:27:46 Pacific
Reply:

Hello, Vidar:

I am having the EXACT same problem you are having, in the EXACT same context! I am also a newbie. Can you spell out exactly what permissions changes you made in order to get things working? Thank you!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP sessions not working

PHP sessions not working www.computing.net/answers/webdevel/php-sessions-not-working/1163.html

php Guestbook not working properly www.computing.net/answers/webdevel/php-guestbook-not-working-properly/719.html

php form not work www.computing.net/answers/webdevel/php-form-not-work/2423.html