Sunday 15 May 2011

php - session id lost when refreshing member page -


I have created a member page that checks in when logged in and contains logout button - see the code below, the developed function ' Code for DBOGGEDEN () 'has been copied from the site - "Section Testing in Log In Users".

For the first time after signing in, the member page with the code below always works when I load it. When I refresh this page again, this session loses information because it has been reported that 'You must be logged in to access this page'. However, when I extract the 'button onclic' line with the session_destroy () in the code below, the member page always works fine.

How do I apply a logout function in the code below, refusing the page will not delete session information? Or is there any mistake in the code that, if fresh, session destroys information?

Please help you thank you in advance

Member page code:

   still logged in"; } And {echo "& lt; br & gt; you are not authorized to access this page"; Echo "& lt; br Error:" $ message; }? & Gt; & Lt ;; DOCTYPE HTML PUBLIC "- // W3C // DTT XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Members Only Page & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; H2 & gt; & Lt ;? Php ek $ message; ? & Gt; & Lt; / H2 & gt; & Lt; Button onclick = "& lt ?? php logout () ;? & gt;" & Gt; Logout & lt; / Button & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

this & lt; Php logout () ;? & Gt; session_destroy () Saying what you should do is linking to the logout page, which calls logout () . HTML / JS can not call the PHP function, they can call only JS function and load url.

  & lt; Button onclick = "document.location = '/ logout.php'; & gt; Logout & lt; / button & gt;   

logout.php:

 < Code> & lt ;? php function logout () {session_destroy (); echo "You have been logged out!";} People out ();    

No comments:

Post a Comment