bonacipher Posted March 13, 2007 Share Posted March 13, 2007 I have a cookie called 'site' which is set during one of my pages: newPhotos.php. It is reset at the top of index.php using setcookie('site'); However if I refrest newPhotos.php, it seems to reset the cookie. I found that commenting out the reset on index.php resolves this behaviour. Similarly, if I put an echo "HERE"; statement before setcookie('site'); on index.php, it does not reset the cookie when I refresh newPhotos.php (because the output means I cannot modify header information.) Fair enough, the only reason that this is of interest is that HERE is not displayed, nor is a warning that I "Cannot modify header information - headers already sent by ".... blah blah So the big question is, how come this header information on index.php is being read, and yet index.php itself is not? I am not including index.php at any point. Very confused, any help much appreciated. ??? ??? ??? Link to comment https://forums.phpfreaks.com/topic/42585-strange-cookie-behaviour/ Share on other sites More sharing options...
tauchai83 Posted March 13, 2007 Share Posted March 13, 2007 hi, could you please post your relevant code? if not how people in this forum help you out? your setcookie/session_start() should be put before any html tag and preferable on the very top of the page after the <?php tag Link to comment https://forums.phpfreaks.com/topic/42585-strange-cookie-behaviour/#findComment-206648 Share on other sites More sharing options...
bonacipher Posted March 13, 2007 Author Share Posted March 13, 2007 I don't think posting code will help, but here it is. I realise that setcookie needs to be before any html output, that is not the problem. The problem is that index.php header information appears to be being called from within an entirely different page, and yet index.php is not included in that page. Thanks in advance for your help. index.php: <?php setcookie('site'); ....etc..... ?> newPhotos.php (where the cookie gets set): $site = ''; if(isset($_GET['site'])){ $site = $_GET['site']; }else if(isset($_COOKIE['site']) && $_COOKIE['site'] != ''){ $site = $_COOKIE['site']; } if($site == 'parkTour2006'){ setcookie('site','parkTour2006'); include_once('./rp/header.php'); }else{ include_once('./includes/header.php'); } newPhotosView.php (where the cookie gets read) <? if(isset($_COOKIE['site']) && $_COOKIE['site'] != ''){ setcookie('site','parkTour2006'); $site = $_COOKIE['site']; if($site == 'parkTour2006'){ include_once('./rp/header.php'); } }else{ include_once('./includes/header.php'); } Link to comment https://forums.phpfreaks.com/topic/42585-strange-cookie-behaviour/#findComment-206660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.