Solved

Session variables retain only the last sesion variable stored

Posted on 2011-09-29
5
234 Views
Last Modified: 2012-06-27
I am using session variables to store data

I am trying to store 4 or 5 variables but seem to only end up with 1 value in the session file

I have attached the session class, some session files and my php.ini
The total contents of a session file where the last thing I set was the the username

$varname|s:8:"johnec50";

The total contents of a session file where the last thing I set was the the user role

$varname|s:5:"Admin";

The total contents of a session file where the last thing I set was the value of "yes" for  a variable called auth

$varname|s:3:"yes";

It looks like the variables overwrite themselves  

Please if you can help


Thanks for reading this

John php.ini
Session.class
0
Comment
Question by:johnecollins
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 36816851
try replacing the line
$_SESSION['$varname'] = $value;
with
$_SESSION[$varname] = $value;

inside your class
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36816855
(in every place where it appears)
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36890846
As implemented, the literal string $varname, not the variable contained in $varname, has become the key into the session array.  Note the different ways of defining strings in PHP.  Please read this page carefully to understand the difference that arises when you use single quotes.
http://php.net/manual/en/language.types.string.php

Also, it looks like the information in the session has been serialized and I do not know of a good design pattern that would include doing that.  The session uses an array named $_SESSION.  Here is everything you need to do to use the session:

<?php
session_start();
$_SESSION["john"] = "collins";
var_dump($_SESSION);

If you're interested in client authentication using PHP, this article shows the essential moving parts.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
 

Author Comment

by:johnecollins
ID: 36893852
Roads_Roads
Is it ok to call you Roads?

Thank you for your solution superb - mind you you knew it would work ;-)

Thanks for your help

Ray, another fine contribution to my efforts I shall read it through.

Thank you both

John
0
 

Author Closing Comment

by:johnecollins
ID: 36893902
Cheers

John
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now