I want to know how to write a php script that run in background in browser when anyone login.
Keep in mind that browsers don't execute PHP - only your server does that.
It depends on what type of script you want to run in the background. You need to give us more information. Speculation is not a good thing.