...you're doing a lot of unnecessarily complicated and somewhat counter-productive stuff. For example, you don't really need to use a custom function to start your session. Then, your StartSession() function destroys any existing session - you're starting a new session each time. Third, the code you posts doesn't actually start a session (you never call your function).
PHP Code:
<?php
// you need to start your session _before_ any output to the user.
// unless you _need_ a custom session id, just let PHP create one itself.
// start the session.
session_start();
// (don't use session_register(). it is deprecated and was actually removed in 5.4.)
// using session variables:
if( empty( $_SESSION ) ){
// if no session exists (i.e., this is the first page visit),
// we'll start with a value of 1.
$_SESSION['view_count'] = 1;
}else{
// if a session exists, we'll increment the view count.
$_SESSION['view_count']++;
}
// then print out how many page views there have been this session:
print "Number of times you have viewed this page during this session: {$_SESSION['view_count']}";
Bookmarks