I would like to use session for my website so i can track the user.But I got confuse on how to use it. Can someone please explain it in details for me?
Basically, at the beginning of every php script you should start the session by session_start(); PHP: A session variable will persist even you click from pages to pages or refresh pages. A session variable can be define as $_SESSSION['myvar']=$_SESSSION['myvar']+1; echo $_SESSSION['myvar']; PHP: For example, the above code will show increasing number each time you refresh your page. But of course, you should google for more practical examples.
You need to put that code just to start a session. But you can not store anything with it, without the complete set as goldensea80 has suggested. <?php session_start(); if(isset($_SESSION['view'])) $_SESSION['view'] = $_SESSION['view']+1; else $_SESSION['view'] = 1; Code (markup): *Forexample if you put that code in your say aboutsession.php file, and then <?php echo $_SESSION['view']; ?> will give you the number of refresh a user is making in your site. it willl give each person who is viewing aboutsession.php everytime a person refreshed the browser, the value will incremebt. It will also help you, when your visitors in your site have to post something to a file/sql in your site it will help you to control the number of posts instead of having people post the same thing over and over, everytime they refresh the page (that happens in php) So, use that script to give each of ur users a uniq id good luck
Thank you everybody for the help! <?php ini_set('display_errors', 1); error_reporting(E_ALL); session_start(); include('dbconn.php'); if(isset($_SESSION['A_id'])) { ?> Code (markup): -this is the code that i put at the top of every page in my website. It is correct? Should I change ($_SESSION['id'] to [$_SESSION['username']? or it doesn't matter which attribute that i want to use?
Many people make this mistake. The website is never told that the browser is being closed, or is going to another site. Either you force the information (using onUnLoad() or one of a few other Javascript event handlers), you set a timeout for the session or you just let the session time out after the default 30 minutes. The web runs disconnected - the site doesn't know what the browser does, other than for the browser telling the site that it wants something. (And "I'm leaving now" isn't something the browser tells the site, since there's no reason for it.)