Post by wrstrong » Tue Oct 06, 2020 2:26 am

Hi there,

I created a simple text-based counter in php and am trying to figure out where to insert it. Every time I try to add it to any of the twig files, it just ignores the script. Can anyone please give me some advice? Any help you could give would be greatly appreciated.

Thanks in advance,

Bill Strong

email:: thelamp.website@yahoo.com


Newbie

Posts

Joined
Tue Feb 16, 2016 8:25 am
Location - Pennsylvania, USA

Post by straightlight » Tue Oct 06, 2020 3:03 am

It's not ignored, you simply need to refresh the cache: viewtopic.php?f=134&t=215776#p718325 .

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wrstrong » Tue Oct 06, 2020 4:18 am

I tried that, but no change. I added the following to the top of the footer.twig:

<center>
<?
$filename = 'counter.txt';

// create the file if it doesn't exist
if (!file_exists($filename)) {
$counter_file = fopen($filename, "w");
fwrite($counter_file, "0");
$counter = 0;
} else {
$counter_file = fopen($filename, "r");

// will read the first line
$counter = fgets($counter_file);
}

// increase $counter
$counter++;

// echo counter
echo $counter . " visitor(s) so far!";

// save the increased counter
fwrite($counter_file, "0");

// close the file
fclose($counter_file);
?>
</center>

email:: thelamp.website@yahoo.com


Newbie

Posts

Joined
Tue Feb 16, 2016 8:25 am
Location - Pennsylvania, USA

Post by OSWorX » Tue Oct 06, 2020 4:25 am

First of all: who really cares how many visitors your site may have?
This was a "modern" gimmick 20 years ago ...

Second; you can't add php-code directly into a twig file.
Third: you never should add such code into a template file (do the logic inside the controller, hand over the result into a variable and call this variable in the template).

And (see this): https://www.opencart.com/index.php?rout ... ch=counter

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by straightlight » Wed Oct 07, 2020 5:47 am

You could also write a /after event and output the results into your footer.twig file so that you don't need nor have to overwrite core files.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 3 guests