Sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pri_4all
Forum Newbie
Posts: 4
Joined: Fri Nov 04, 2011 8:48 am

Sessions

Post 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.
Last edited by Benjamin on Mon Nov 14, 2011 10:31 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Sessions

Post 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'];
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply