[PHP] Session handling problems

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
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.
 
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 profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back