Question About Php

Discussion in 'PHP' started by assetsunset, Jan 20, 2013.

  1. #1
    Hi,

    I have a file in which I would like a number of codes to rotate on time based intervals. I would like to include a new file where I can add the codes.

    So basically for instance I have index.php. In this file I include codes.php. Now I would like to add say 60 codes inside codes.php and they must rotate evenly each month. So each code much display like 12 hours each month.

    Example:
    index.php

    <?php
    include 'codes.php';
    $accountKey = ' rotating key!!!!!!! ';
    ?>

    codes.php
    <?php
    $key1 = 'nRcEEgie0wXk3MpEQJfCvIeriXPlE7iHUV2zE0NZkgY=';
    $key2 = 'wbJSp+4pTQCmw6F2y4JPlZlwDIpkIhiN64jTcCf4xxM=';
    etc
    ?>

    Can someone help me out here?

    Thanks!
     
    Solved! View solution.
    assetsunset, Jan 20, 2013 IP
  2. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #2
    You want show first code first 12 hours, then 12 hours - second code? Or show codes randomly, but same numbers of times per month for each code?

    And small note, you should set your codes as array:
    <?php
    $keys = array(
        'nRcEEgie0wXk3MpEQJfCvIeriXPlE7iHUV2zE0NZkgY=',
        'wbJSp+4pTQCmw6F2y4JPlZlwDIpkIhiN64jTcCf4xxM=',
    );
    ?>
    PHP:
     
    Sano000, Jan 20, 2013 IP
  3. assetsunset

    assetsunset Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #3
    I want to show the codes randomly yes. And do you mean I have to set them as an array inside the include file?
     
    assetsunset, Jan 20, 2013 IP
  4. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #4
    Easiest way will be to show random code from the array. Number of hits per month will be approximately equal to each other. For example:
    <?php
    // codes.php
    function get_code() {
        $keys = array(
            'code1',
            'code2',
            'code3',
        ); 
        return $keys[rand(0, count($keys)-1)];
    }
    ?>
    PHP:
    <?php
    //index.php
    include 'codes.php';
     
    echo get_code();
     
    ?>
    PHP:
     
    Sano000, Jan 20, 2013 IP
  5. assetsunset

    assetsunset Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #5
    How should I add echo get_code();
    inside
    $accountKey = 'nRcEEgie0wXk3MpEQJfCvIeriXPlE7iHUV2zE0NZkgY=';

    Thanks.
     
    assetsunset, Jan 20, 2013 IP
  6. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #6
    $accountKey = ' rotating key is '.get_code().'!!!!!!! '[/COLOR][/FONT][/SIZE][SIZE=3][FONT=courier new][COLOR=#000000]
    PHP:
     
    Sano000, Jan 20, 2013 IP
  7. assetsunset

    assetsunset Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #7
    You mean like this:
    $accountKey = 'get_code()'
     
    assetsunset, Jan 20, 2013 IP
  8. #8
    No, get_code() is function
    $accountKey = get_code();
     
    Sano000, Jan 20, 2013 IP
  9. assetsunset

    assetsunset Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    3
    #9
    Aha ok, thanks for your help buddy. Very kind!
     
    assetsunset, Jan 20, 2013 IP