ochi Posted February 1, 2010 Share Posted February 1, 2010 Hello, I would like to know if it is possible activate a $_SESSION variable in a link: echo "<a href = logout.php > Logout </a> ; I want activate $_SESSION['logout'] when the link is pressed, so, before than redirect to logout.php I do, $_SESSION['logout'] = true Thanks. Regards! Link to comment https://forums.phpfreaks.com/topic/190510-activate-_session-variable/ Share on other sites More sharing options...
jl5501 Posted February 1, 2010 Share Posted February 1, 2010 You cannot set a session variable until the processing returns to the server, as they are set only by PHP code. You could have it as the first thing the logout.php does, but not before processing goes to a php file. Link to comment https://forums.phpfreaks.com/topic/190510-activate-_session-variable/#findComment-1004888 Share on other sites More sharing options...
ochi Posted February 1, 2010 Author Share Posted February 1, 2010 Ops, ok, I'll tell you what I want to do, it cant be so difficult!!!! My structure is: index.php (with user/password autentication) and page2.php and logout.php I want to forbid users write in the browser: http://xx.xx.xx.xx/page2.php it should redirect to index.php. I suposse that the solution is $_SESSION variables, but it's not as simple as it looks. If I activate $_SESSION['page2'] when the user introduce the correct user and password, but he close the browser before than puss the "page2" link, this variable is set and the next time the browser is open it'll be possible write http://xx.xx.xx.xx/page2.php Thanks! regards Link to comment https://forums.phpfreaks.com/topic/190510-activate-_session-variable/#findComment-1004891 Share on other sites More sharing options...
jl5501 Posted February 1, 2010 Share Posted February 1, 2010 To do this, the user will either have to clear the session by using your code to do so in the logout.php script, or have it timeout which is controlled by the session_timeout in the php.ini file. Link to comment https://forums.phpfreaks.com/topic/190510-activate-_session-variable/#findComment-1004892 Share on other sites More sharing options...
ochi Posted February 1, 2010 Author Share Posted February 1, 2010 Hello again, in my php.ini "session_timeout" doesnt exist. I was looking for it in google, and i found that it is: session.gc_maxlifetime I change it to 60 (seconds as it's said in php.ini), after this I tried it waiting for 2 minutes: if(isset($_SESSION['auth'])){ echo "session establised"; } and "session establised" is writed. Other thing: ; Lifetime in seconds of cookie or, if 0, until browser is restarted. session.cookie_lifetime = 0 When I close the browser and open it again, SESSION variables should exist? they do. Thanks. REgards Link to comment https://forums.phpfreaks.com/topic/190510-activate-_session-variable/#findComment-1004904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.