Home  Extras  MODx Add-Ons  session counter

session counter



Forums Support Thread Votes: 12
Tags: Navigation, snippet
Submitted: Aug 24, 2007
Released: Aug 24, 2007
Downloads: 587
License: Public Domain


session counter 0.9 | Author: andrea

Works with the following Version(s): 0.9.6

Simple php grafic counter with session


Download


Description

Do you want a counter for your site? This is the solution. With one snippet you can put the counter on your site, and choose from 2 type of counter, text or grafic.
The counter use the session.

Instructions

//////////////////////////////////////////////////////////
//
// PASTE THE CONTENTS OF THIS FILE INTO MODx WHEN INSTALLING THIS SNIPPET
//
// Snippet Name: contatore
// Short Description: Grafic/Text Counter
// Version: 0.9
// Author: andrea
//
// Note:
// -----
// You can use this snippet in anyway you want. Modify it's code, lend some parts of it or whatever you want to do with it.
// If you are going to make changes to some other files that this snippet uses, make sure you keep the author informations intact at the code.
//
// Copyright & Licencing:
// ----------------------
// GNU General Public License (GPL) (http://www.gnu.org/copyleft/gpl.html)
//
// English Instructions:
//------------------------------
// 1) Copy the folder "contatore" in the web site root
// 2) Create a new snippet called "contatore"
// 3) Use the snippet with this command
// 4) you can change the type of counter modifying the variable $visual --- see below
//
// Istruzioni in italiano:
//-----------------------------
// 1) Copiare la cartella "contatore" nella root principale del sito web
// 2) Creare un nuovo snippet di nome "contatore"
// 3) Utilizzare lo snippet nel templatre richiamandolo col seguente comando
// 4) puoi modificare il tipo di contatore modificando la variabile $visual --- guarda sotto
////////////////////////////////////////////////////////////////////////////////////////////////////////



<?php
session_start();

$pathtxt="contatore/counter.txt"; //Path del file txt per salvare le info del counter.
$visual="text"; //Tipo di counter "text" per testuale e "img" per grafico!
$pathimg="http://localhost/pontelandolfonews.com/contatore/img/"; //Path immagini per il counter grafico!



@ $sessione = $_SESSION'session_id';

if ($sessione == "sessione"){


$fp=fopen("$pathtxt","r+") OR DIE ("impossibile aprire il file");
flock($fp,2);
$countxt=fgets($fp,1024);
flock($fp,3);

//visualizza il counter
if($visual=='text'){
echo"$countxt";}else{
$lenght=strlen($countxt);
$contimg=array();
for($i=0;$i < $lenght;$i++){$contimg$i = substr($countxt,$i,1); }
for ($i = 0;$i < $lenght;$i++){
$countimg= "<img src="".$pathimg."/".$contimg$i.".gif""
." alt="".$contimg$i."">";

echo"$countimg";}}





}else {
$_SESSION'session_id'="sessione";
//Scrivo



$fp=fopen("$pathtxt","r+") OR DIE ("impossibile aprire il file");
flock($fp,2);
$countxt=fgets($fp,1024);
flock($fp,3);

$countxt++;

$fp=fopen("$pathtxt","w+") OR DIE ("impossibile aprire il file");
flock($fp,2);
fputs($fp,"$countxt");
flock($fp,3);
fclose($fp);

//visualizza il counter
if($visual=='text'){
echo"$countxt";}else{
$lenght=strlen($countxt);
$contimg=array();
for($i=0;$i < $lenght;$i++){$contimg$i = substr($countxt,$i,1); }
for ($i = 0;$i < $lenght;$i++){
$countimg= "<img src="".$pathimg."/".$contimg$i.".gif""
." alt="".$contimg$i."">";

echo"$countimg";}}

}
?>




Sub-Packages



Previous Releases



Comments

Please login to comment.

Close ]


 
 
 

Contact Us | Team Blog | FAQ | Site Credits

© 2005-2009 the MODx CMS project. All rights reserved. Privacy Policy | Terms of Service