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

passthru() help
Hi everyone,
I'm new to the forum and to PHP. I have some pretty good experience writing shell sc

Filtering an Array Based on Value
I have a very simple script set up that pulls data from a database and is output using this code:

RSS feed - FeedList for WordPress
Hi,

I'm trying to alter the FeedList plugin for WordPress so that I can click on the title of

Retail terminologys not been altered after activing Retail System
Hi, All

After I active Retail System via TCode SWF5, the terms does not been changed, th

Greek characters in php
Hi,

I'm making a script and I m using for first time greek characters.
I started to write

Operator precedence assistance.
I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand,

FPDF Help
I've been playing with the FPDF module. I was building a form and rolling right along and then sudde

str_replace help
I am thinking str_replace is my only option to filter outputs from my database to convert them to sa

Need help PLEASE
ok i have this warning showing up

Warning: in_array() [function.in-array]: Wrong datatype for

Gaining access to Drop Down Menu Variable
code is below, I am creating a drop down menu. I want to echo the value selected in the drop down me

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