I have a website that displays images from an array. The index number of the array (1-150) is returned by a session variable counting up for every page view. Easy so far. My problem is that I want the user to be able to get back to the place they were in the 150 images if they leave and return to the site later. So I thought of putting a cookie on their computer which the index page could look up when they come back. Does that make sense?
Anyway, every time the viewing page is loaded the session variable counter clicks on by one, loading the next image. What I want to do is give them a button to push to go to a page which sends a cookie with the session number on it. So the code for the cookie sending page is this:
Code: Select all
<?php
setcookie('bm_danny', 0, mktime(), "/");
session_start();
$_SESSION['page'] = $_SESSION['page']-1;
echo "page = ". $_SESSION['page'];
$_COOKIE['bm_danny'] = &$_SESSION['page'];
echo "cookie = ". $_COOKIE['bm_danny'];
?>Anyone know where I'm going wrong?
Code: Select all
<?php
echo "page = ". $_COOKIE['bm_danny'];
if ($_COOKIE['bm_danny'] > 0) {
echo '<p><a href="danny/page.php"> continue reading </a></p>';
}
else {
echo '<p><a href="danny/first_page.php"> Read </a></p>';
}
?>