Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PHP counter

darthmoobeydarthmoobey Posts: 140Member
I have an issue here, I Am not too familiar with PHP, but say I am making a gameing website. And people are creating characters. Is there a method of creating a counter, that every "DAY" that is 24 hour span that the server will automatically update the character's "XP" or experience. I am having trouble trying to find an algo with PHP on this. How do we let the server know to use this daily in other words?

The Darthmoob

Comments

  • fnoyanfnoyan Posts: 103Member
    : I have an issue here, I Am not too familiar with PHP, but say I am making a gameing website. And people are creating characters. Is there a method of creating a counter, that every "DAY" that is 24 hour span that the server will automatically update the character's "XP" or experience. I am having trouble trying to find an algo with PHP on this. How do we let the server know to use this daily in other words?
    :
    : The Darthmoob

    Hi
    This may help...
    First of all save the creation date of character. And compare the date with current date. So you will get your characters age. Once you calculate the character's age you can assign a new XP value by the mehod below:
    create a database table like this
    +-----------+--------------+------------+-----+
    | CharName | CreationDate | UpdateDate | Exp |
    +-----------+--------------+------------+-----+
    | fnoyan | 08.03.2004 | 21.03.2004 | 0.8 |
    +-----------+--------------+------------+-----+
    .....
    .....
    You have already had the character's age. Write a function that calculates the XP value for each day or hour (your choice). And update the database table's "UpdateDate" and "Exp" fields. Do this when the character is used by the creator.

    Hope this helps....
  • skylarskylar Posts: 82Member
    I have the same problem as you darth, i am making a game as well and wanted to do the same.. Problem is, it is VERY BAD to make a php code run ALL THE TIME and it is impossible to have it start on it's own (i think)

    You need a program such as pirch or mirc.

    Then use timers to goto a update php file.. when the file is opened it will run all of your updates.

    I've tested it and it works for me.

    Now the problem is, you will always need to have that program running on your computer =


    If you have any problems with it, give me a holler and get a lot more in depth with you on this subject.

    skylar011@hotmail.com (msn)
    sky_@email.com
    skylar@starreign.net <- my new game site (not near completed)
    Im getting my domain today so it might not work yet lol

    www.starreign.net

    [b][blue]Snoochie Boochies[/blue][/b]

  • skylarskylar Posts: 82Member
    [b][red]This message was edited by skylar at 2004-3-23 14:41:47[/red][/b][hr]
    You could also do it like this:

    [code]
    mainphpscriptfile.php

    <?php
    $f = file("lastupdate.txt");
    $f = implode(chr(10), $f);

    if(time() - $f > 86400){
    include("updater.php");
    $pointer = fopen("lastupdate.php", "w");
    fwrite($pointer, time());
    fclose($pointer);
    }

    ...
    ----
    rest of main script file
    ----

    [/code]

    This is not a very good method if you have a lot of users or a lot of requests. Opening files is hard on the server if it has to do it a couple or more times a second for instance. But it would be fine for game of less than 100 users.

    Just make sure that you set lastupdate to the beginning of the hour the update should take place otherwise it will do it every hour (in the middle of the hour lol)

    [b][blue]Snoochie Boochies[/blue][/b]







  • mtman65mtman65 Posts: 7Member
    Depending on your host, you should check out information on cron, it allows you to run a program at a set time. So you could write a program to update all characters at say midnight every night and have it automatically execute everyday.





    : I have an issue here, I Am not too familiar with PHP, but say I am making a gameing website. And people are creating characters. Is there a method of creating a counter, that every "DAY" that is 24 hour span that the server will automatically update the character's "XP" or experience. I am having trouble trying to find an algo with PHP on this. How do we let the server know to use this daily in other words?
    :
    : The Darthmoob
    :

  • annyphpannyphp Posts: 6Member
    Free and Open Source [link=http://www.phpkode.com/scripts/category/php-counters/]PHP Counter[/link] script show you a image based, text based or real-time counter to help you check the status of your site.
    PHP counter is a web-based counter written in PHP, It is a multi-counter tracking system that logs visitor data and statistics in real time.
    A hit counter is a PHP counter script that counts the number of times and a web page has been accessed. This allows both the owener of the page and visitors to know how popular the page is . A simple hit counter can be created with PHP in just nine lines of code.
    The PHP Counter that I recommend can only count the number of times the page has been accessed. It cannot count the number of unique visitors. The PHP hit counter simply updates a text file, which keeps track of the number of times the page is accessed. The PHP Script read the current the file, then adds one to the number, writes the number to the file and close the file. The script is then embedded into the html on the web page so that it is executed each time the page is accessed.
    The hit counter script looks like this:
    <?php
    $filename = "hits.txt";
    $count= file($filename);
    $count[0]++;
    $file = fopen ($filename, "w") or die ("Cannot find $filename");
    fputs($file, "$count[0]");
    fclose($file);
    echo $count[0];
    ?>
Sign In or Register to comment.