1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Help - Creating an Online Lottery

Discussion in 'PHP' started by Sarah Paris, Jan 4, 2014.

  1. #1
    Hello everyone I am new to this forum so I am glad to meet all of you. I am new to PHP and am trying to code my own online instant lottery program.

    Basically the PHP program will generate a viewable ticket book of 100 random numbers, with a control panel having the ability to choose which numbers are winning numbers and what the prize is for each winning number.

    I want the program to be able to instantly payout via Paypal to winning lottery ticket purchasers and instantly provide ticket(s) upon payment for them.

    I invite anyone knowledgeable in PHP to post code snippets, advice for how to PHP program might work, code structure, etc. I will post more as I do more work on the program.

    Regards
     
    Sarah Paris, Jan 4, 2014 IP
  2. BeltHosting

    BeltHosting Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    You need to manipulate random numbers, since it's not really that random or is it? You can have 5 members with whatever you offer and pick only one of them. rand(min,max) will come handy. Payouts can be done via PayPal IPN. Look it up on google.
     
    BeltHosting, Jan 5, 2014 IP
  3. HolyRoller

    HolyRoller Well-Known Member

    Messages:
    552
    Likes Received:
    27
    Best Answers:
    1
    Trophy Points:
    150
    #3
    I would probably avoid automatic payout to start with, a small bug or security hole could leave your paypal account wide open. Why do people need to be paid instantly? could you not store how much money they have won against their username and just have a withdrawal process?
     
    HolyRoller, Jan 6, 2014 IP
  4. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #4
    Check the legalities before wasting your time on development
     
    NetStar, Jan 6, 2014 IP
    ryan_uk likes this.
  5. Sarah Paris

    Sarah Paris Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    The array of random numbers will be saved to a file for reading.

    I want the program to have the convenience of automatic withdrawal and purchasing. That is what will keep customers coming back.

    Legal or not I have it hosted and worked on offshore.

    Here is the preliminary code I have put down (I am brand new to PHP and am just starting to learn)

    
    <?php
    
    //random number array generator code 1-100 randomized and saved to a text file
    
    
    //list of winning numbers 
    
    $winningno = 7;
    $winningno1 = 2;
    $winningno2 = 22;
    $winningno3 = 11;
    $winningno4 = 69;
    $winningno5 = 50;
    $winningno6 = 13;
    $winningno7 = 9;
    $winningno8 = 35;
    $winningno9 = 19;
    $winningno10 = 20;
    $winningno11 = 42;
    $winningno12 = 76;
    $winningno13 = 24;
    $winningno14 = 89;
    $winningno15 = 87;
    $winningno16 = 91;
    $winningno17 = 93;
    $winningno18 = 4;
    $winningno19 = 0;
    
    //purchasing script 
    
    for (i = 1 to numberofticketsbought){
    
    $lotteryno = x; //the line of the array that the program is currently on. purchasing a ticket corresponds to the line of the array the program is currently on
    
    //comparison code
    
    echo 'Your number is ' $lotteryno;
    if ($lotteryno = $winningno(1-10)){
    echo 'you won 5 dollars! ';
    payout(5);
    }
    else if($lotteryno = $winningno(11-16){
    echo 'you won 20 dollars! ';
    payout(15);
    }
    else if($lotteryno = $winningno(17-18){
    echo 'you won 50 dollars! ';
    payout(50);
    }
    else if($lotteryno = $winningno(19){
    echo 'you won 100 dollars! ';
    payout(100);
    }
    else{
    echo 'aww you lost :( maybe you should buy another ticket ';
    }
    
    next i;
    
    
    ?>
    Code (markup):
    Thank you for all your responses!! Please contribute more if you'd like :)
     
    Sarah Paris, Jan 10, 2014 IP
  6. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #6
    After seeing the code I realized the legalities won't matter. It'll never make it to production.

    Are you just starting out with programming and this is for fun? Or is this something you think is going to generate money?
     
    NetStar, Jan 10, 2014 IP
  7. Sarah Paris

    Sarah Paris Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    I am brand new to PHP and have limited coding experience from years and years ago. I plan to borrow code to complete the entire project and find help wherever I can.
     
    Sarah Paris, Jan 10, 2014 IP
  8. StrongCoffee

    StrongCoffee Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #8
    Hi Sarah, I mostly hate saying "you won't be able to make it", since that mostly depends on how motivated you are. But I have to be honest with you: stop developing this thing yourself, it's for your own good. This idea you have, without looking at the legals, is severely depended on how well it's written and secured. If you are dedicated on writing this by yourself, please, put this in the fridge and start on easier projects first and familirise yourself in the field of webdevelopment first. If you're not obliged to write this by yourself, please, find a professional to write it up.

    I wish you the best of luck!
     
    StrongCoffee, Jan 11, 2014 IP
  9. Sarah Paris

    Sarah Paris Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    The concepts aren't that hard correct? There's an array which contains a certain amount of winning numbers, a paypal plugin to pay for each number in the array, and another paypal plugin for instant payment if the winning number matches the number bought in the array? I understand there is a little bit of coding in there but I'm new to PHP, not to coding in general. I've messed around with Visual Basic 6 and Java back in the day :(
     
    Sarah Paris, Jan 11, 2014 IP
  10. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #10
    Who cares if you've "messed around" with VB and Java "back in the day". That is irrelevant. That's like a runner entering the Olympics because he "messed around" with track and field back in high school. It's just running right?

    Judging solely based on the code you written you lack the ability to properly design a program. You can use bits and pieces of other peoples code and mash it together with insecure entry level php code all you want but it will not result in a quality product. You're right it does seem simple. So does the concept of FaceBook and Twitter as well.

    Your biggest obstacle is writing secure code and developing a SECURE system that is bug free. You don't even have an algorithm in place and you want to automate a lottery payout system. You're simply setting yourself up for failure.
     
    NetStar, Jan 11, 2014 IP
    malky66 likes this.
  11. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #11
    First of all - running a 1-100 lottery seems futile when it comes to making money of this, if the tickets doesn't cost 10-15-50-100 $ each. First you need to set a total amount of numbers (say a 1000), and then calculate the cost of running the site and making it, and then calculate the total amount of winnings (of these 1000 tickets, there's a total of say 10 winning numbers, ranging from 5 to a 100 $ in winnings - hence, say you have 1 ticket worth 100, 2 tickets worth 20, 3 tickets worth 10 and 4 tickets worth 5 - that's a total of 190$ in winnings, which means you need to charge at least 20 cents pr. ticket to come out ahead only based on the winnings itself - say 50 cents a ticket to get a bit of overhead).
    When that's all taken care of (the calculations), you need to rethink your code.
    There's no need to create a random number sequence - you just need to pull a random number out of the sequence (say a sequence from 1 - 1000) - and then store that number somewhere, in connection to the user, perhaps, if you want to have some sort of history etc. But at least you need to store the number so that the same number isn't drawn twice.
    So you have something like the following:
    List of numbers (total amount of tickets): 1 - 1000
    Selected winning numbers (can be arbitrary, can be randomly generated): array[3,8,12,24,26,33,51,70,80,92]
    Then you need logic to create a random number between 1 and 1000
    Then you need to check that number against the array of winning numbers
    Then you need to store the number, preferably in a database, and use those numbers stored to limit which numbers can be pulled from the total amount of tickets
    On top of that, you need a user-authentication setup - login, user-credentials, etc.
    And secure connections to Paypal and similar payment-processors

    The idea is simple - the design and calculations are fairly simple too, but can be built upon for quite a while, and then you need to secure the product so that it's properly secure against hacking, stealing of funds, etc.
     
    PoPSiCLe, Jan 12, 2014 IP
  12. Sarah Paris

    Sarah Paris Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #12
    The ticket price for starting tickets is 5 dollars. There will be a 24 percent chance of winnings with 350$ out of the 500$ grossed from ticket sales going to lottery prizes. I wrote the ideas and bits of code in the above code to keep track of how I want the program to work - that was my original design for the program. Thanks to Pupsickle for contributing positively. I understand what he is talking about it and helps me to think about how I want my program to work.

    I am indeed learning PHP and I hope to become better at it and want to learn as much as I can throughout this project. But I don't mind borrowing others' code to complete it; I will put forth my best effort and integrity to make it a quality product for both myself and my audience.
     
    Sarah Paris, Jan 13, 2014 IP
  13. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #13
    Just take note that a total of $500 in lottery tickets, and a payout of $350 might see you quickly going broke - this is based on the law of averages, more than the actual code (which can prevent this, at least somewhat). It all depends on how legitimate you wanna do it. If you limit the amount of winnings based on how many tickets are sold, for instance, that's perfectly legal, but maybe not a good incentive for buyers.
    What I'm saying is this: if you have a number-series going from 1-100, and sell tickets for $5 each, you might, in the worst case, get someone buying 10 tickets (ie, $50), and cashing out on multiple tickets, including first price - hence putting you at a loss (until more users pay for more tickets, which they might not do, if you tell them which prices has been won - which is a decent thing to do, at least).
    I understand that, if you wanna make this an actual thing, you expect more than one set of tickets, perhaps, and also probably more tickets pr. lottery etc., I'm just saying that from what you're saying, the math (for the income/expense) isn't completely sound. You usually take the expected cost, top that with any taxes or similar, and then multiply that sum with say somewhere between 1,2 and 1,5 to get the amount you need to sell something for - hence, I think perhaps the total winnings need to be slightly lower, or the amount of tickets increased somewhat to cover possible unexpected expenses etc.
     
    PoPSiCLe, Jan 15, 2014 IP
  14. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #14
    While the major components of this script aren't that hard for people who have been coding for a while that doesn't necessarily mean they will be easy for you. And when you're doing anything related to paying out money etc. it needs to be 100% secure, and if you don't even know how to make a basic version of this site I don't think you know enough to even make this remotely secure.
     
    Pudge1, Jan 20, 2014 IP