Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Countdown with php ?

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #32642
    The-Marshal
    Member

    Can you please tell me a way to make a countdown with php

    and when i refresh the page don’t start from the beginning!!!

    it’s continue.

    #77158
    TheDoc
    Member

    What are you trying to countdown? Is the countdown specific to a user?

    #77141
    The-Marshal
    Member

    Yes,
    I’ve a group of users and in the their CPanel i want them to know how many days they still have.

    #77059
    TheDoc
    Member

    Then it won’t really be a ‘countdown’, per se.

    I assume each user has a location in a database somewhere. In that table I would create a new column for ‘user_expiry’ and make a call to that.

    I’m not knowledgeable enough in programming to help you further, but that’s the direction I’d go.

    #77061
    The-Marshal
    Member

    thanx TheDoc ,

    what i need a countdown in php like:

    chris = > user he take hosting from my server and the period 3 month,

    so when he open his cpanel he will see how many days he still have

    but the problem i have is when i refresh the page count from the beginning

    have a look to this page

    http://greatworks.eu5.org/count2/

    Thanx again TheDoc .

    #77069
    TheDoc
    Member

    Right, the script on that page isn’t connecting to a database, so it will have no idea when the expiration date actually is.

    The expiry date of the account will have to be stored somewhere (database).

    #75018
    The-Marshal
    Member

    ok i found this fancy script

    Countdown
    could you please make YEAR, MONTH, DAY only

    i think here change the value


    $date = array();
    $date = $diffSecs % 60;
    $date = floor($diffSecs/60)%60;
    $date = floor($diffSecs/60/60)%24;
    $date = floor($diffSecs/60/60/24)%7;
    $date = floor($diffSecs/60/60/24/7);

    i tried month like this


    $date = floor($diffSecs/60/60/24/7)%30;

    but didn’t working

    I appreciate any help

    #74952
    ddliu
    Member

    I agree with @TheDoc, at least you have to get user data from database(including when will the account expire).

    Assuming you have got it and put it into a PHP variable “$expiration” and the format is UNIX timestamp.

    So next you can use $expiration to calculate useful infomation:

    1. Get the expiration date:


    echo "Your account will be expired on ".date('m/d/Y',$expiration);

    The output will be something like:
    Your account will be expired on 06/01/2012

    Read PHP manual to get more information on date: http://php.net/manual/en/function.date.php

    2. Get datetime differenc


    $diffSecs=$expiration-time();
    ...//continue with your countdown script...

    #74946
    The-Marshal
    Member

    thanx ddliu

    really i don’t want to use this script as opening for my website but to my clients

    to know how many days they still have .

    this script has config page so i take the info from my database


    $id = $row->id;
    $year = $row->year;
    $Month = $row->Month;
    $day = $row->day;
    $message = $row->message;

    $config = array(
    'targetDate' => array( // Target countdown date
    'day' => $day,
    'month' => $Month,
    'year' => $year,
    'hour' => 0,
    'minute' => 0,
    'second' => 0
    )
    );

    and display it in control page of my client as a countdown

    so i want this script to display year, month, day only

    i tried but i face some problems and i need this script as soon as possible.

    #74940
    ddliu
    Member

    Sorry I don’t quite understand what is your problem.

    Can you get expiration information from database?

    Can you calculate how long(e.g. how many days) will it expire?

    Do you have problem displaying it in the web page?

    Anyway, I can show you a function might be helpful: https://gist.github.com/1000031


    function getDateDiff($date)
    {
    $diff_info=array();
    $timestamp=strtotime($date);
    $timestamp_diff=$timestamp-time();

    //test if $date is future
    $diff_info=$timestamp_diff>0;

    $timestamp_diff=abs($timestamp_diff);

    //calculate total date difference
    $date_diff=round($timestamp_diff/(24*3600));

    //year
    $diff_info=floor($date_diff/365);
    $date_diff-=$diff_info*365;

    //month
    $diff_info=floor($date_diff/30.5);
    $date_diff-=floor($diff_info*30.5);

    //day
    $diff_info=$date_diff;

    return $diff_info;
    }

    and how to use it:


    $diff=getDateDiff('8/12/2012');
    if($diff)
    {
    echo "You have {$diff} year(s), {$diff} month(s), {$diff} day(s) left";
    }
    else
    {
    echo "Your account has expired";
    }
    #74899
    The-Marshal
    Member

    Thank you ddliu your script is fantastic i use it and get the variables from database

    and it’s work thanx again you are awesome..☺

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘Back End’ is closed to new topics and replies.