limitphp Posted February 2, 2009 Share Posted February 2, 2009 Ok, I figured out why it is happening....please look at the second post. It appears that a pagination link is changing a cookie value. I put the site up on the live site so you could see it: www.greckle.com Under: Top Songs (All Genres) click on Past 365 days. Then click on Next, to goto page 2 and you'll see that it changes the time back to 60 days. The time is handled by a querystring and cookie value with this code: <?php if($_GET['time']) //*****Get Existing time Value { $time = $_GET['time']; } elseif($_COOKIE['time']) { $time = $_COOKIE['time']; } //Validate $time = ceil($time); if(empty($time) || !is_numeric($time) || $time < 1 || $time>365) { $time = 60; } //Set Cookie for next time setcookie("time",$time, 0); So, when you first goto the site, by default its set to 60 days. then when you click on 365, it sets it to 365 and sets the cookie to 365. You can see that clicking on Next does NOT send a querystring to change it back to 60, so I have NO idea how thats happening. It doesn' make any sense. I tested to make sure that when you clicked on Next, that $time was getting its new value from the cookie, and it was. Here's the code for the Next link: <?php if ($currentpage<$totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo "<a href='page$nextpage/' class='pagination-link'><div align='center' class='pagination-div'>Next »</div></a>"; } else{ echo "<div align='center' class='pagination-grayed-div'><font class='pagination-grayed-text'>Next »</font></div>"; } I've been looking at this and thinking about this since Friday. I'm stuck and I really need your help on this, please. Let me know if you need me to post anymore pieces of code to look at. Thank you. Link to comment https://forums.phpfreaks.com/topic/143462-solved-pagination-changing-cookie-value-despartely-need-help/ Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 I think I know what the problem is! I just looked at the cookies..... Ok, first when you goto the site it sets the cookie 60 days under the path greckle/ then when you click on Next it sets the cookie 365 under the path: greckle/page2/ How do i fix this to set all cookies under the path: greckle/ ? In other words, the mod rewrite is causing it to set the time cookie in 2 different places! Link to comment https://forums.phpfreaks.com/topic/143462-solved-pagination-changing-cookie-value-despartely-need-help/#findComment-752530 Share on other sites More sharing options...
limitphp Posted February 2, 2009 Author Share Posted February 2, 2009 Ok, I solved the problem.....by setting the path in the setcookie: setcookie("time",$time, 0, $path_set); Link to comment https://forums.phpfreaks.com/topic/143462-solved-pagination-changing-cookie-value-despartely-need-help/#findComment-752586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.