stuckwithcode Posted February 3, 2010 Share Posted February 3, 2010 Hello, When a user leaves my web page I would like to run some php code, is this possible. Any suggestions are appreciated Quote Link to comment https://forums.phpfreaks.com/topic/190784-can-this-be-done/ Share on other sites More sharing options...
gwolgamott Posted February 3, 2010 Share Posted February 3, 2010 Server-side language. So no (BUT yes) I'd like to say, but using something like a client side language to start a php program maybe. But beyond the scope of strictly php for every time a user leaves a web page. If you require them to do something like click a link or a button then u can run the script in that sense for saying log out or whatever, but php always need somethin from the client side to tell something on the server to run. So look into javascript perhaps to force a php script on the server to run if you wanting to run a tracker for example. Also don't ask can but how with a better subject, will get more responses. Now with that said, what exactly are you wanting to do? Quote Link to comment https://forums.phpfreaks.com/topic/190784-can-this-be-done/#findComment-1006042 Share on other sites More sharing options...
oni-kun Posted February 3, 2010 Share Posted February 3, 2010 Hello, When a user leaves my web page I would like to run some php code, is this possible. Any suggestions are appreciated The simple answer is No. PHP is a server side language, JS (On some browsers, not all to warn you) There is a JS event on abort, but this cannot be done in PHP. As mentioned by previous poster, I would not recommend setting up an automated session check, the logic is flawed. You can use AJAX event along with the onAbort (or whatever it is), but this isn't the place to ask. Quote Link to comment https://forums.phpfreaks.com/topic/190784-can-this-be-done/#findComment-1006043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.