Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2003, 11:14 PM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default Sessions

i'm a newbie, and i can't get my sessions to work!
i want them for a login script.

here is what i have processing the info after login:
    session_start();
    session_register("username","level");
    $_SESSION['username']=$username;
    $_SESSION['level']=$level;
then i tried accessing this information from another page using
$_SESSION['username']
.......but it wasn't there

----------------------------
Oh happyland!
__________________
----------------------------
Aeon of Darkness MUD - Free Online Roleplaying Game
http://aeonofdarkness.com
 
Old June 14th, 2003, 03:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Moharo
Default

try this:


session_start();
session_register("level");
session_register("username");
$_SESSION["level"] = "levelvariable";
$_SESSION["username"] = "usernamevariable";

this should work... (access variable thru $_SESSION array)


the genuine genius
 
Old June 14th, 2003, 11:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

well i tried what you said and used several variations because i wasn't sure for some of it, but it didn't work.

i tried:
$_SESSION["level"] = "level";
$_SESSION["username"] = "username";
and
$_SESSION["level"] = "$level";
$_SESSION["username"] = "$username";
and
$_SESSION["level"] = $level;
$_SESSION["username"] = $username;


and then tried accessing the session variables using $_SESSION["username"] and $_SESSION['username']
but it didn't work
i didn't get any errors, it just acted like the sessions didn't exist, maybe i didn't properly initialize them

but i also wanted to know how to delete the session when i wanted. i have tried these so far:
$_SESSION['username']=NULL;
$_SESSION['level']=NULL;
and
session_unregister("username");
session_unregister("level");
and
session_destroy();
(when i used session_destroy it said: "Warning: Trying to destroy uninitialized")

----------------------------
Oh happyland!
 
Old June 14th, 2003, 12:33 PM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

well nevermind, i figured it out, i needed session_start() as the first line of every website i wanted to access the session variables. it works perfectly now :) thanks for all your help!

----------------------------
Oh happyland!
 
Old June 19th, 2003, 02:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Follow up -- do _NOT_ use session_register() or session_unregister(). Don't pollute your global scope with session variables. Doing this is not only sloppy, it also introduces some security risks.

Stick with $_SESSION only.

<?php
session_start(); // required for ANY page using sessions.

$_SESSION['username'] = "nikolai";

unset($_SESSION['username']); // replaces session_unregister()
?>


Take care,

Nik
http://www.bigaction.org/
 
Old June 19th, 2003, 03:52 PM
Authorized User
 
Join Date: Jun 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to natmaster Send a message via AIM to natmaster Send a message via MSN to natmaster
Default

what does session_destroy(); do?

----------------------------
Oh happyland!
 
Old March 5th, 2004, 05:24 AM
Authorized User
 
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default

session_detroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie :)

 
Old March 12th, 2004, 04:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

http://www.php.net/session_destroy

The best place to look for a description of a function (especially when you KNOW the function name) is the documentation.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions p2ptolu Classic ASP Components 3 March 17th, 2005 06:31 AM
Sessions 2540EA BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 20th, 2005 05:42 AM
Mixing classic ASP sessions with ASP.NET sessions scorpion_king General .NET 2 August 4th, 2004 08:20 AM
Sessions aeejai Beginning PHP 3 April 22nd, 2004 01:51 PM
Help sessions ittorget Pro VB 6 2 April 20th, 2004 02:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.