Ok so i have 2 pages one where the user can view it as a slide show and one where they can view it as a list using <table>
So i come to the idea of using the list incase the user does not have high speed net and thought it might take them a while to actually load the slide... so they have the option just to view it as a list. So upon this i was thinking to myself well if they want to view it as a list then i need it to go back to the list when they re-visit the site rather than going to the default page (where the slide show is) so i thought cookies would do the trick!
So here i have it
index.php containing:
PHP Code:
<?php
if(isset($_COOKIE['viewinglist']))
header( 'Location: indexlist.php' ) ;
else
?>
If there is a cookie there then redirect them to indexlist.
So now in indexlist.php i got:
PHP Code:
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
$value = "Viewing as list";
setcookie('viewinglist', $value, $inTwoMonths);
?>
We are setting the cookie so they have entered the page so when it goes to index it will read this cookie to show they should be on indexlist.php and it will redirect them to there.
Ok... so now, the user has just clicked the view as slide show!
this will take the user to:
PHP Code:
includes/viewasslide.php
which contains code to "delete" the cookie or if you like "set it to a date before the now time...
PHP Code:
<?php
//Killing the cookie:
$cookie_name="viewinglist";
//here we assign a "0" value to the cookie, i.e. disabling the cookie:
$cookie_value="";
//When deleting a cookie you should assure that the expiration date is in the past,
//to trigger the removal mechanism in your browser.
$cookie_expire=time()-60;
$cookie_domain="";
setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain,0);
//re-direct to login screen (or any other you like):
header( "Location:../index.php");
exit;
?>
Now the problem is when i click this link and run this script its not actually deleting it or resetting the value to a previous time and keeps taking me back to indexlist.php where really it should be on index.php.
I cant see myself where its wrong but it obviously is. Could someone point out where im wrong? Thanks