Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2068 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Php Counting Script

Thread title: Php Counting Script
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
03-29-2007, 01:46 AM
#1
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old  Php Counting Script

I'm looking for a script that when a viewer looks at the page it will add one to the previous number that there was. Mainly refreshing, it will add a number. I also need it to clear when you leave the page. Maybe sessions? I know php well, but I cant seem to get this. I know I need something like $email + 1 = $emails idk something like that but it never works.. just takes it and adds one and then thats it.. doesnt keep adding, I also need to be able to have more than one counter on the same page. Maybe having the counter name as a random integer, something like that. I'm thinking.

Code:
<?php
$email = "1";
$emails = $email + 1;

echo $emails;
?>
something like that to just keep adding one from on...over and over and then clear when the page is closed, or when you click a button. maybe make it redirect and then before it redirects clears the thing, or assigns a new id for the counter and then clears all the counters when you close the page.

MSN/Email: jomar@carolina.rr.com

03-29-2007, 02:11 AM
#2
aLx is offline aLx
Status: Senior Member
Join date: Jan 2006
Location: USA
Expertise:
Software:
 
Posts: 922
iTrader: 13 / 100%
 

aLx is on a distinguished road

Send a message via AIM to aLx

  Old

Use a while loop, php.net

03-29-2007, 02:55 AM
#3
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

I have looked at a lot of tutorials, and also I have tried everything. Can someone please give me an example or anything to help me get on the right track.

03-29-2007, 07:31 PM
#4
localhost is offline localhost
localhost's Avatar
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
 
Posts: 1,316
iTrader: 17 / 100%
 

localhost is on a distinguished road

  Old

well what exactly are you looking for something that counts the number of page refreshes.. Will write you a small script soon possibly using sessions.

03-29-2007, 09:36 PM
#5
Cooleo is offline Cooleo
Status: Member
Join date: Sep 2005
Location: Stoke, UK
Expertise:
Software:
 
Posts: 151
iTrader: 0 / 0%
 

Cooleo is on a distinguished road

Send a message via MSN to Cooleo

  Old

<?php
ob_start();
session_start();

if(!$_GET['clear']){
$_SESSION['emails'] = 0;
$_SESSION['emails']++;
} else {
$_SESSION['emails'] = 0;
header("Location: ".$_SERVER['PHP_SELF']);
}

echo $_SESSION['emails'];
?>

To clear it, add ?clear=1 to the filename/

03-29-2007, 09:52 PM
#6
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

just giving me straight 1's no matter how many times I refresh it.

03-29-2007, 09:55 PM
#7
Cooleo is offline Cooleo
Status: Member
Join date: Sep 2005
Location: Stoke, UK
Expertise:
Software:
 
Posts: 151
iTrader: 0 / 0%
 

Cooleo is on a distinguished road

Send a message via MSN to Cooleo

  Old

damn, sorry - its late here & i've had a long day (i'm setting the value to 0 then adding 1 to it each time, heres the new code:

<?php
ob_start();
session_start();

if(!$_SESSION['emails']){
$_SESSION['emails'] = 0;
}

if(!$_GET['clear']){
$_SESSION['emails']++;
} else {
$_SESSION['emails'] = 0;
header("Location: ".$_SERVER['PHP_SELF']);
}

echo $_SESSION['emails'];
?>

03-29-2007, 10:08 PM
#8
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

ok your awesome... How do I clear it and maybe is it possible to make it to where I can have more than one up so they dont interfere with eachother?

03-29-2007, 10:13 PM
#9
Cooleo is offline Cooleo
Status: Member
Join date: Sep 2005
Location: Stoke, UK
Expertise:
Software:
 
Posts: 151
iTrader: 0 / 0%
 

Cooleo is on a distinguished road

Send a message via MSN to Cooleo

  Old

<?php
ob_start();
session_start();
$self = $_SERVER['PHP_SELF'];

if(!$_SESSION['count-'.$self]){
$_SESSION['emails'] = 0;
}

if(!$_GET['clear']){
$_SESSION['count-'.$self]++;
} else {
$_SESSION['count-'.$self] = 0;
header("Location: ".$self);
}

echo $_SESSION['count-'.$self];
?>


This script will have its own counter for each file.


To clear:
if the script was called c1.php
clear the count by accessing c1.php?clear=1

03-29-2007, 10:24 PM
#10
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

everytime i start a new one that is already running it just resets the other one that is already running to restart back at 1.. I made it so that whenever it redirectes to the other redirecting.. itll also clear the field.. so everytime I start a new one, it will reset it back to 1, it seems that like all the sessions are named the same, maybe by giving it a name of a random integer or something.

Code:
if ( $_SESSION['count-'.$self]++ )
   {
      $_SESSION['count-'.$self] = 0;
   }

Closed Thread  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed