SchweppesAle Posted October 15, 2009 Share Posted October 15, 2009 Just started getting into the use of cookies. The following code will redirect users to a set URL should they view a preset number of pages. I'm a little concerned with the speed in which this executes though. Is there a better way, or this fine? public function onPrepareContent(&$article, &$params, $limitstart) { global $mainframe; $content = $article -> text; $current = JURI::current(); $duration = $this->params->get('duration'); $destination = $this->params->get('destination'); $max_count = $this->params->get('maxcount'); $site_id = 'aseihthaslhetlasiehtlasndlksahdlv'; $value = 1; if(!(isset($_COOKIE["$site_id"]))) { setcookie("$site_id", $value, time() + 60 * 60 * 24 * $duration); } if(isset($_COOKIE["$site_id"])) { $increment = TRUE; if($_COOKIE["$site_id"] > $max_count) { $value = 1; setcookie("$site_id", $value, time() + 60 * 60 * 24 * $duration); $increment = FALSE; header("Location: $destination"); } if($increment) { $value = $_COOKIE["$site_id"]; $value++; setcookie("$site_id", $value, time() + 60 * 60 * 24 * $duration); /*$content = $_COOKIE["$site_id"];*/ } } $article -> text = $content; } Link to comment https://forums.phpfreaks.com/topic/177844-optimize-code/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.