• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[PHP] Session handling problems

#1
According to many PHP manuals on the net, this should work:

Code:
session_start();

$user = $_GET['user'];
session_register("user");

print $user;
What I want to do, is first get $user (with $_GET) from the address line with session.php?user=Glaanieboy. Next I want to register $user to the current session, so the variable $user will still contain the value of "Glaanieboy", just like session were invented for. But for some reason, this above code won't work.
It works when I use ?user=Glaanieboy, but when I leave the ?(etc) bit away, it prints nothing. Why? I have registered $user, right?
I remember doing this ages ago, but unfortunately I deleted the files in question.
 
J

Jason2k1

Guest
#2
I think the following will do what you want:
PHP:
<?php
session_start();

if (isset($_SESSION['user'])){

$user = $_SESSION['user'];

}else{

$_SESSION['user'] = $_GET['user'];

$user = $_GET['user'];
}

print $user;
?>
 

Members online

No members online now.

Latest posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,012
Latest member
Sierge