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;

}

138 Like 43 Dislike
Previous php-forum Next php-forum
Other php-forum

Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter

Variable passed to each() is not an array or object
Hi,

This is a email a friend type of form, and it isn't working anymore.

<?

Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there

Two fgetcsv related questions ;D
First of im trying to get a file from a merchants server but the directory is protected, I know the

Help? Need help on project with templates involving mysql and php.
I'm having a hard time explaining what I want but basically here is what I have in place:

-Da

PEAR Email Attachment w/ $gpg
I have no issues with this code if I take out the attachement section and include the info in the em

please hep to get values from a table row
can anyone tel me how I can select and get data from one row by pressing an Edit button in that row

Adding delete feature to my forum
Hello I am currently trying to add a delete feature to my forum. I believe I have everything built r

switch form actions? not working
i want on submit to go to different pages according to the CatID

Code: <?php $CatID=$_

How to load mysql (and other) extensions into PHP
How to load mysql (and other) extensions into PHP PHP Development forum discussing coding practices,

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