pixeloft pixeloft - 1 year ago 108
PHP Question

Fix Illegal string offset after PHP update

I updated my PHP version, and have been getting this error on most of my pages:

Warning: Illegal string offset in "..." on line 236

After googling and trouble-shooting for hours, I've found that the error is because a variable within an array is being read as a string. I'm clueless as to how to fix this. Please help!

This is the line of code that is causing the error:

if(isset($_SESSION['email']) && $_SESSION['email']['loggedIn']){ ... } else { ... }

Answer Source

This could be because $_SESSION["email"] contains a string, not an array so $_SESSION["email"]["loggedIn"] fails.

You should check first is_array($_SESSION["email"])

if(isset($_SESSION['email']) && is_array($_SESSION["email"] && $_SESSION['email']['loggedIn'])

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download