会话开始时运行脚本? [关闭]

How do I run a script (ie, $viewcount += 1;) when a session starts in PHP? I'm trying to make a view counter script for my website which currently works, assuming I include('view_counter.php') in every page to add something to my text file of views. Unfortunately, people can reload the page and so add up the view count really quickly. What I'd like to do is add to the view count every time somebody opens a new session on the site. It should be obvious, but how do I do it?

Just check if the Session object exists or not yet using an IF statement, and if it doesn't, it means it's a new session in which you can run your counter code.

More info on working with sessions: Check whether a session is new in PHP