Hello, I have a web site protected with an user and a password, they are asked in index.php and if they are correct jump to page2.php My problem is: if I write in the browser: http://www.server.com/page2.php I can enter, and I jump the user/password control. I want redirect all the posibilities to the index.php, I'm trying it with ,htaccess, but I can't, I redirect always, also if I write the user and password correct. How can I do it? Thank you! Regards!
Hi, here is one solution for your problem. You need to work out database connection for user names and passwords. But this can be your starting point.. View attachment login_logout_demo.zip Rudolf p.s. username : demo password : demo
Simple redirect would not work, you need to do session handling. As Rudolf Bodocsi suggested, implement login, logout methods
hello, thank you for your help, but i tried this with in a differents ways and it doesnt work. First of all I have more than 2 pages, but it is not important. Think about it: index.php -> user authenticate ok, so, I active $_SESSION['auth_page2'] but I dont redirect it as in the example by Rudolf, user has to puss a link, but he close the browser instead of puss the link or "logout" one, so, the variable is set, and if user writes: http://xx.xx.xx.xx/page2.php he would enter. Isn't a configuration option in Apache? I cant believe this! Thank you! Regards
hello, thank you for your help, but i tried this with in a differents ways and it doesnt work. First of all I have more than 2 pages, but it is not important. Think about it: index.php -> user authenticate ok, so, I active $_SESSION['auth_page2'] but I dont redirect it as in the example by Rudolf, user has to puss a link, but he close the browser instead of puss the link or "logout" one, so, the variable is set, and if user writes: http://xx.xx.xx.xx/page2.php he would enter. Isn't a configuration option in Apache? I cant believe this! Thank you! Regards
It's not problem. Just you need insert PHP code from page2.php to your extra pages. If user close web browser then session will be destroyed automatically. The problem could be if user just close tab in web browser. But you can solve problem with small java script. If user closing web page then destroy session. Rudolf
Yes, there is no problem with 2 or 1000 pages, we agree. The problem with the tab/browser, it is not as you comment, my mozilla is configurated to "remember" the open tabs when I close it, and if I have page2.php open and close mozilla, when I open it again, it still have the SESSION variable. I'm looking about the javascript, this is what I have: <script type="text/javascript"> window.onbeforeunload = function delete(){ session_destroy(); //this is incorrect!!!! window.close(); } </script> Code (markup): <body onunload="delete();"> HTML: do you know where is my problem? I think that it wont work, because javascript is Client-side and php server-side, but if you are so sure, could you tell me how??? Thanks!
Hi, I found out for you what was a problem. This java script should be work. I tested every variation and I can't reach page2.php after when I closed my web browser or tab. <script type="text/javascript"> window.onbeforeunload = function delete(){ <?php session_destroy(); ?> window.close(); } </script> Code (markup): Here is a modified page2 : View attachment page2.php Rudolf
Thanks! it worked! I thought that it was impossible insert any php code in javascript... I see I was wrong. But now, with this code I have a new problem, onunload is executed when the tab is closed but also when a link is used, do it exist another html function? Thanks!
Erm....wouldn't it just be easier to have the session expire after a certain amount of time has passed? See: http://php.net/manual/en/function.session-set-cookie-params.php http://php.net/manual/en/function.session-cache-expire.php That way you don't need to worry about javascript (which can be disabled thus rendered worthless)
Yes, I'm also implemented this, but it's not so easy in my case, because most of links call javascript functions instead of php files. Thanks!!!