forum

Home / DeveloperSection / Forums / Illegal string offset warning using session

Illegal string offset warning using session

Anonymous User271301-Nov-2014

I'm trying to set session in my program, after the user has logged with his account. If user input good email and password, then program set some variables, like this:

$_SESSION['user']['id']= $row['id']; $_SESSION['user']['email']= $email; $_SESSION['user']['admin']= $row['admin']; $_SESSION['logged']=true;

The problem is, that I'm getting this  warning from first three rows of code above:

Warning: Illegal string offset 'id' in C:\Program Files (x86)\Zend\Apache2\htdocs\OOPeshop\user\User.php on line 193

So I checked, if all the variables are set, so i add to my code this two lines:

var_dump($row); var_dump($email);

but it was looking alright, I was getting output

array(2){["id"]=>string(2)"14"["admin"]=>string(1)"0"}

string(22) "foobar@gmail.com"

So can someone explain me where is the problem? I checked similar question, but found  no solution to my problem.

I have tried this:

$user = array('id'=> $row['id'],'email'=> $email,'admin'=> $row['admin']); $_SESSION['user']= $user;

No more warnings. It set array first and then set whole array to session variable, it worked, but i don't know where's problem in my first code, so maybe someone with a better understanding can explain it better.


Updated on 01-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By