TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-01-2008, 08:55 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default simple session question

Hi.

Can I set $_SESSION['something'] to the value of an array?

PHP Code:
$array = array('name' => Tanax'site' => 'TALKPHP');

$_SESSION['admin'] = $array;

echo 
$_SESSION['admin']['name']; 

???
Tanax is offline  
Reply With Quote
Old 01-01-2008, 09:16 PM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

anyways i dident read your question corectly
now i get what you where asking..
and yes you can set a session to the value of an array.

as tlcandres said

sorry once again :P

Last edited by codefreek : 01-01-2008 at 09:33 PM. Reason: EDIT
codefreek is offline  
Reply With Quote
The Following User Says Thank You to codefreek For This Useful Post:
Tanax (01-01-2008)
Old 01-01-2008, 09:25 PM   #3 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

yes you can set a session to the value of an array.
TlcAndres is offline  
Reply With Quote
The Following 2 Users Say Thank You to TlcAndres For This Useful Post:
codefreek (01-01-2008), Tanax (01-01-2008)
Old 01-01-2008, 10:36 PM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Thanks :)
Tanax is offline  
Reply With Quote
Old 01-01-2008, 11:24 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,258
Thanks: 90
Wildhoney is on a distinguished road
Default

To the array itself? Your code will work. One question though, why didn't you just run it yourself and see? Just curious.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-02-2008, 01:36 AM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

I could be wrong, but wouldn't assigning the array to the session just be a pointer? You couldn't use it on another page since its stored in the ram which is deleted at the end of th pages execution. I know in C/++ (what php is made in), the root variable for an array is a pointer.

Or on the off chance that that memory address is being used by the time you go the next page it displays that.
__________________

Village Idiot is offline  
Reply With Quote
Old 01-02-2008, 01:44 AM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,324
Thanks: 5
Salathe is on a distinguished road
Default

In reply to Village Idiot's post, session variables are serialized (ie, formatted into one long string) before being stored physically (in the file system, database, etc.). Some types of variables can't be stored in sessions -- things that can't be serialized -- such as resources or objects with circular references, but most variable types have no problem being saved as session data.
Salathe is offline  
Reply With Quote
Old 01-02-2008, 01:45 AM   #8 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,296
Thanks: 17
Village Idiot is on a distinguished road
Default

Ah, I see.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design