Solved

Session variables retain only the last sesion variable stored

Posted on 2011-09-29
5
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

737 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