Page 1 of 1

Sessions

Posted: Mon Nov 14, 2011 9:05 am
by pri_4all
I have written four php files and linked them. I want a session which stores the path from where i come to that page(all the pages i viewed). how should i write and include a session in the files so that it stores the path. The session should capture all the pages i viewed. Please help i am not good with sessions.


1.Referer file

Code: Select all

<?php
echo "<p> Referred by : ".basename($_SERVER['HTTP_REFERER'],".php");

?>
2.index file

Code: Select all

<html.
<body>
<?php

require "referer.php";
?>
<h1>Index</h1>
<a href="aboutus.php">link</a>

</body>
</html>
3.Aboutus file

Code: Select all

<html.
<body>
<?php
require "referer.php";
?>
<h1>About us</h1>
<a href="services.php">link</a>
</body>
</html>

4.Services file

Code: Select all

<html.
<body>
<?php
require "referer.php";
?>
<h1>Services</h1>
<a href="Index.php">link</a>
</body>
</html>

thankyou.

Re: Sessions

Posted: Mon Nov 14, 2011 3:47 pm
by social_experiment
You'll need session_start() on all the pages, before anything else is echoed to the browers if you want to use sessions. To capture all the pages you visit you can use an array and add each page to the array as a new page is accessed.

Code: Select all

<?php
 session_start();
 $_SESSION['referers'][] = $_SERVER['HTTP_REFERER'];
?>