Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Storing arrays in sessions - help!
Old 03-26-2009, 11:22 AM Storing arrays in sessions - help!
Average Talker

Posts: 15
Name: Declan Dowling
Trades: 0
Hello.. again!

I'm having some trouble storing an array as a session, and then retrieving it and adding a value using array_push().

PHP Code:
$dealer_cards    = array($dealer_1$dealer_2);
$player_cards    = array($player_1$player_2);

$_SESSION['player_cards']    = $player_cards;
$_SESSION['dealer_cards']    = $dealer_cards;

/// ^This part works.

$player_cards $_SESSION['player_cards']);
$dealer_cards $_SESSION['dealer_cards']);

$player_new   $dealer->deal();
$player_cards array_push($player_cards$player_new);

/// ^This part doesn't.
/// Anybody... ? 
Thanks in advance to anybody who helps!
Declan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-26-2009, 02:18 PM Re: Storing arrays in sessions - help!
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Try this:

PHP Code:
session_start(); // added this, not sure it it was started correctly.

$dealer_cards    = array($dealer_1$dealer_2);
$player_cards    = array($player_1$player_2);

$_SESSION['player_cards']    = serialize($player_cards);
$_SESSION['dealer_cards']    = serialize($dealer_cards);

/// ^This part works.

$player_cards unserialize($_SESSION['player_cards']); // there were extra brackets on these. check if your hiding errors.
$dealer_cards unserialize($_SESSION['dealer_cards']);

$player_new   $dealer->deal();
$player_cards array_push($player_cards$player_new); 
http://uk2.php.net/manual/en/function.serialize.php

I added comments to the bits I added/noted.

You could also add base64_encode/decode onto that serialize if you want.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 03-26-2009 at 02:19 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Storing arrays in sessions - help!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10560 seconds with 12 queries