jyothi Posted March 15, 2010 Report Share Posted March 15, 2010 Hi I want to know in PHP, if session can be used to help in this. Create browsing history page of website. When user browse through pages of website at the end user can see which pages he browsed. Reply required. I will be grateful. If it can happen can u let me know the examples of it Thanks Jyothi Quote Link to comment Share on other sites More sharing options...
administrator Posted March 15, 2010 Report Share Posted March 15, 2010 Hi, 1. Create a session on every page you want to track. 2. You need to first grab the current page the user is on .. using something like: $_SERVER["REQUEST_URI"]; 3. You need to add the current page to the session array with each page the user lands on. 4. Now that you have the pages visited in session, you can display them back to the user. The code: <?php session_start(); $_SESSION['pages'] = $_SERVER["REQUEST_URI"]; // store session data echo "Pages Visited = ". $_SESSION['pages']; //display pages visited ?> I did not test this - so there maybe typos. Stefan Quote Link to comment Share on other sites More sharing options...
jyothi Posted March 16, 2010 Author Report Share Posted March 16, 2010 Hi, 1. Create a session on every page you want to track. 2. You need to first grab the current page the user is on .. using something like: $_SERVER["REQUEST_URI"]; 3. You need to add the current page to the session array with each page the user lands on. 4. Now that you have the pages visited in session, you can display them back to the user. The code: <?php session_start(); $_SESSION['pages'] = $_SERVER["REQUEST_URI"]; // store session data echo "Pages Visited = ". $_SESSION['pages']; //display pages visited ?> I did not test this - so there maybe typos. Stefan ------------ Thanks a lot. Your example really helped me Jyothi Quote Link to comment Share on other sites More sharing options...
srinivasa Posted March 25, 2010 Report Share Posted March 25, 2010 I have added the following line in four different pages(for ex: session.php,myproduct.php,myage.php,twologout.php) $_SESSION['pages'] = $_SERVER["REQUEST_URI"]; i want to display all the four uri in one page say history.php tel me how to display,i tried but dint get the answer.......... so plz giv me ur suggestion...thanks in advance Quote Link to comment Share on other sites More sharing options...
administrator Posted March 25, 2010 Report Share Posted March 25, 2010 Hi, If you store multiple pieces of information in a PHP session, you need to use a loop to display them all: <?php session_start(); // loop through the session with foreach foreach($_SESSION as $key=>$value) { // print out the values stored in session echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />'; } ?> And on each page, you would use the session to store the user visit to the page. I just looked at the code I used in my first answer and there is an error ... I wrote: session_start(); $_SESSION['pages'] = $_SERVER["REQUEST_URI"]; // store session data echo "Pages Visited = ". $_SESSION['pages']; //display pages visited ?> You need to give each session entry it's own key: session_start(); $_SESSION['$_SERVER["REQUEST_URI"]'] = $_SERVER["REQUEST_URI"]; // store session data echo "Pages Visited = ". $_SESSION['pages']; //display pages visited ?> .. Sorry about that, sometimes I make silly mistakes when writing quickly and I also mix things up from language to language. Quote Link to comment Share on other sites More sharing options...
srinivasa Posted March 25, 2010 Report Share Posted March 25, 2010 Thanks a lot............... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.