Home > DeveloperSection > Forums > How to use session in PHP?
Pravesh Singh

Total Post:411

Posted on    March-12-2012 2:21 AM


 1 Reply(s)
 1634  View(s)
Rate this:
I want to show page view in my php page, So could you explain how to solve this problem using session. Please reply as soon as possible.

Arun Singh

Total Post:68

Posted on    March-12-2012 8:17 AM

Hello Pravesh,
A PHP session variable is used to store information about, or change settings for a user session. Before you can store user information in your PHP session, you must first start up the session. session_start() function is used for start session into PHP page.

To resolve your problem you can try something like following code.
PHP Script Code:


// Start Session


// check session value has been set or not

if(isset ($_SESSION['PageViewUser']))


    // increment counter by 1 if session value is already set

    $_SESSION['PageViewUser'] = $_SESSION['PageViewUser']+ 1 ;




    // if session value not set, then value set by 1 in session variable

    $_SESSION['PageViewUser'] = $_SESSION['PageViewUser']+1 ;

} ?>

For more details about Session or Session Variable in PHP visit this URL:

Don't want to miss updates? Please click the below button!

Follow MindStick