PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 14, 2022

[FIXED] Session doesn't work on MAMP

 February 14, 2022     localhost, mamp, php, session     No comments   

Issue

When i try to run my site on localhost i get an error:

Undefined index: log in ... on line 137

Within this file there is a line:

if (!$_SESSION['log']) { ...

Everything works on server, but not on localhost. What can I do to fix it?


Solution

There is probably a difference between the level of error reporting between the server and your local setup.

If you want to check if the variable is set (assuming that a session has been started...), you should use:

if (!isset($_SESSION['log'])) {

Or if you want to check if it is not set and / or empty or false:

if (empty($_SESSION['log'])) {

Both will not generate any warnings for non-set variables or array indices.



Answered By - jeroen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing