I don’t know the context of your login page (if it’s standalone or included in another page, etc.) but you’ll need to put the code as early as possible in the page. You could try putting it all the way at the top of login-page.php and see if it does something.
@EliteZERO – if you want more help, you’re going to have to describe your problem in more detail..
“It doesn’t work” is useless information – after all, if it did work, would you still be asking for help? You need to tell us what actually happens, vs. what you expect. It is also helpful to share the code in question (this doesn’t work too well in the discussion forums – you can post code on pastebin or moke a gist on github).
Also, since no one mentioned this. This is a header function meaning no output can be sent before the header function is called. So if say you have an additional page outputting a header for the layout or any other html or output is released before the header() function the script will fail.
Hi, this is my login page. Where should I put the code.
The forum isn’t a great place to share large amounts of code. As you can see, a lot of your code will be mangled and won’t display correctly. You might try pastebin or make a gist on github instead, and then share the link.
To answer your question, in general, something like this should appear as close to the beginning of your script as possible. As @BradMetcalf mentioned, if there is any output to the browser beforehand, the header function won’t work. Since you’re getting the request to log out via $_REQUEST, then it’s probably safe to say that it could be the first thing you do.