Solved

Session variables retain only the last sesion variable stored

Posted on 2011-09-29
5
259 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 109

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
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 …

856 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