1

Is it safe for me to use in live website?

member.php

if($_SESSION['login'] == 1)
//member stuff

$_SESSION['login'] is set after user authenticate via login.php

phpnewbie
  • 43
  • 1
  • 4

5 Answers5

1

Session security in PHP is often asked about - see PHP Session Security for pretty good answers.

Community
  • 1
  • 1
Shadikka
  • 4,116
  • 2
  • 16
  • 19
1

In general: yes. You may want to set a bit more variables, but sessions are only available to php and not the user. The part where it gets exciting in terms of security is how you handle your authentication.

Arend
  • 3,741
  • 2
  • 27
  • 37
0

Yes, you should check if $_SESSION is set too.

if(isset($_SESSION['login'])) { ...
    if($_SESSION['login'] == 1) { ...
Otto
  • 4,020
  • 6
  • 35
  • 46
  • 1
    nested ifs? `if( isset($_SESSION['login']) && $_SESSION['login'] == 1 )` The right hand part of the expression isn't evaluated if the left hand is false, so no notice will be generated – Erik Jun 06 '11 at 16:55
0

It's safe as the $_SESSION state is stored on your server, not sent back to the client.

Steve Mayne
  • 22,285
  • 4
  • 49
  • 49
0

Using sessions is better than using cookies when checking for logins/authentication since they can be altered as it communicates with the server from client side when session are only used for server side reading.

MacMac
  • 34,294
  • 55
  • 151
  • 222