php login

Asked

Viewed 259 times

0

I would like when arriving at the page with session only one user with certain login but error when I access

php code:

if($_SESSION['login'] == 'admin')
{
echo "logado";
}

It gives error on the part of Session in if, as if it had not.

2 answers

3

You have to put a condition for when enter it check if the Session exists, try:

if(isset($_SESSION['login']))

will probably solve

  • that’s right! Thank you!

0

The correct is to check the isset and then compare the string

if(isset($_SESSION['login']) && $_SESSION['login'] == 'admin')
{
   echo "logado";
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.