I am working using cookie. My client wants when a visitor visits his site, it will be automatically checked that he visited this site before.If he visited this site before, he will be auto redirected the site he visited before. If he doesn't visited this site before, cookie will be saved that if he will visited this site in future, he will be redirected his last visited page. For example, A site has many category or topic such as Food, Cloth etc. If a visitor visits this site in Cloth topic or category, cookie will be saved. Next time he visits this site, he will be automatically redirected cloth category page cause in past, he visited that page. But this time, a option in footer to save cookie again and if he click to accept cookie, cookie will be saved updated. Now i am trying to do this in localhost and shared it's file. Please check what's the problem or where. Here i use redirect option in header.php and face problem. If i use redirect option in index.php, error occurs ( see screenshot). If i use in header.php, error occurs in every page. See screenshot: http://prntscr.com/cbkux6You can visit this site for an example: http://www.louisvuitton.com/
my header page
<?php if(isset($_COOKIE['saveexperice'])){ $link = $_COOKIE['saveexperice']; header("Location: $link"); exit;}else{ header('Location: http://localhost/cookie'); $exlink = $_SERVER['PHP_SELF']; setcookie('saveexperice', $exlink, time()+60*60*24*30); exit;}
My Index page
<?php include("header.php");//$page_link = $_SERVER['PHP_SELF']; echo "Index page";//echo $page_link;print_r($_COOKIE);include("footer.php");
footer page
<a href="clearcooke.php">Logout</a>
Another page
<?php include("header.php");print_r($_COOKIE);echo "Ex php page";include("footer.php");
cookie clear page
<?php $exlink = $_SERVER['PHP_SELF'];setcookie('saveexperice', $exlink, time()-60*60*24*30);header('location: index.php');
another page
<?php include("header.php");print_r($_COOKIE);echo "CK php page";include("footer.php");
You can download this full project zip file