You should let PHP do the session management for you. If you set it up properly it will use cookies if the client permits it or append it to the url if cookies are refused. You can also have PHP automatically append the session_id for you if cookies are rejected.
You would need to have the following in php.ini to do what I'm suggesting:
; Whether to use cookies.
session.use_cookies = 1
; use transient sid support if enabled by compiling with --enable-trans-sid.
session.use_trans_sid = 1
Then all you have to do is "session_start();" at the top of every page you want to track and PHP will handle the rest.