session - php $_SESSION doesn't work -


this question has answer here:

i'm trying use sessions learning purposes it's not working. got login page passes post "uname" , "passw" page:

<!doctype html public “-//w3c//dtd html 4.01 transitional//en”> <html> <?php session_start(); ?> <head> ... if($_post['uname']=="admin" && $_post['passw']=="correctpassword"){ $_session['login']="ok";}     if($_session['login']=="ok"){ echo "<p>logged in</p>"; } else { echo "<p>nothing</p>"; } ... </html> 

and works until here. when pass on page:

<!doctype html public “-//w3c//dtd html 4.01 transitional//en”> <html> <?php session_start(); ?> <head> ... if($_session['login']=="ok"){ echo "<p>logged in</p>"; } else { echo "<p>nothing</p>"; ... </html> 

and here doesn't work.

i'm working on mamp , safari.

can me please?

place <?php session_start(); ?> on top of page without space before

note: use cookie-based sessions, session_start() must called before outputing browser.


Comments