Jump to content

PHP session


jyothi

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...