Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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'];
etcPage 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

"
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.

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

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.

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

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.

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 OKHave a nice weekend!

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!

![]() |
![]() |
![]() |

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