Optimize Code


Posted on 16th Feb 2014 07:03 pm by admin

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?

Code: [Select]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;

}

No comments posted yet

Your Answer:

Login to answer
138 Like 43 Dislike
Previous forums Next forums
Other forums

Captcha problem users just refresh and it will let them auto submit again
Users will just re submit and not have to enter the new captcha.. ? Lol but if i refresh the page, t

Pagination
Okay here is the page in question: http://blenderteachings.000a.biz/tutorials.hamishhill.php

Most basic form question ever?
Hello,

I want to use this snippet to make sure the fields in a form are ok before processing

PHP and MySQL on intranet?
Is it possible to use both these on an intranet network?

Gantt Chart Tool
Does anyone know of a good free gantt chart creator tool

Thanks

Why does my php page download images over and over
Can anybody please explain to me why my php page keeps downloading the images and other items every

All possible combinations of String in PL/SQL
Hi All,

Could you please explain the logic of getting all possible combinations of String

PHP submit form script causing blank page
Im trying to submit a form using this script, however nothing shows up on the page, does anyone know

Big O & time complexity ???
can you help me how to calculate the Big O & time complexity for any algorithm and c++ program pleas

PHP Blog help
Need help with posting comments in a word press blog? I have a comments page where the comments are

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash