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)

Did you know?Explore Trending and Topic pages for more stories like this.
{

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

PHP Form to Variable.
Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work s

single page with referrer to show correct page
I have a simple website with a couple of different pages. I would like to be able to in a div tag w

PHP & MS Access - Line Break
Hey Guys!

I'm pulling records from an MS Access database and listing them using PHP and I'm r

Cant display mysql data
Hey all,

I am learning php and my first goal is to create a simple CMS. At the moment I am st

insert/update functions for mysql, what do you think?
I am working on two really simple functions that automatically generate (and execute) insert and upd

Word filter problem
Hello,

im trying to make a filter for words inputted in to my website but i want to store the

Sub-domains & calling unique content
Hello,

Is there a way use something similar to the $_GET function for a sub-domain? I to be a

mysql UNION | warning mysql_fetch_array !!
Code: <?php
$i = 0;
$query1="SELECT * FROM `products` WHERE `div

what business processes?
Hi,

A general question. What business processes (like OTC - Order to Cach, P2P, R2R etc)

Where do I put CRON code
So I've figured out alot about how to automatically run a php function. I can't figure out where to

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