Pin Number Downloads - How?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jakeruston
    New Member
    • Oct 2006
    • 10

    Pin Number Downloads - How?

    Hello,

    Firstly, i would just like to say this is my first time on this site, and it looks rather cool and helpful!

    Now, i need a script that:

    [HTML]-When the customer purchases a product, a random pin number is given to them automatically by E-MAIL (which they insert in the shop form).

    -Then, when they go on to the product page, they insert the pin number - Checks to see if the pin is valid, and what product it belongs to.

    -The protected download file starts downloading.

    -The pin number is then deleted out of the database/data file.[/HTML]

    I have never used PHP before, so can somebody help me out here?

    Thanks,
    Jake.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    The following sample is from the php.net documentation's PHP Rand function
    [PHP]<?php

    function randomkeys($len gth)
    {
    $pattern = "1234567890abcd efghijklmnopqrs tuvwxyz";
    for($i=0;$i<$le ngth;$i++)
    {
    $key .= $pattern{rand(0 ,35)};
    }
    return $key;
    }

    echo randomkeys(8)," <br>";
    echo randomkeys(16), "<br>";
    echo randomkeys(32), "<br>";
    echo randomkeys(64), "<br>";

    ?>

    output:

    n94bv1h7
    y9qi1qu2us3wged 2
    00dhax4x68028q9 6yyoypizjb2frgt tp
    478d4ab0ikapaiv 0hk9838qd076q1y f46nh0ysigds6ob 2xtl61odq2nx8dx 7t2b
    [/PHP]

    Ronald :cool:

    Comment

    • jakeruston
      New Member
      • Oct 2006
      • 10

      #3
      Thanks! Okay then, so that is the first step.

      Now, i need to create a database that holds all of the pin numbers. How?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        I don't think it is a good iedea to create a table with reserved numbers. Instead it is better to create the number dynamically when the order is placed and you heberate the email.
        You would have to, to start with, create a table named 'references' such as
        Code:
        CREATE TABLE references (id INT PRIMARY KEY AUTO_INCREMENT,
        date_time TIMESTAMP,
        reference_code VARCHAR(40), 
        product_id VARCHAR(10))
        Then your (very crude) HL design would look like:
        Code:
        If order is submitted:
        -  obtain product_id of ordered item
        -  generate reference_code
        -  store reference_code, date_time and product_id in table 'references'
        -  create email (with reference_id in link)
        -  send email
        When user places order:
        -  get reference_id from url
        -  read reference_id and product_id from table 'references'
        -  if not valid reference_id: issue error message and exit
        -  if valid reference:
           - prepare product download
           - download product
           - clear entry from table 'references'
        Be aware that this forum is to help you, not to write code for you. You have to do that yourself. So, in case you have to brush-up your programming skills, do so before you go on with this. Good luck!

        Ronald :cool:

        Comment

        • jakeruston
          New Member
          • Oct 2006
          • 10

          #5
          Originally posted by ronverdonk
          I don't think it is a good iedea to create a table with reserved numbers. Instead it is better to create the number dynamically when the order is placed and you heberate the email.
          You would have to, to start with, create a table named 'references' such as
          Code:
          CREATE TABLE references (id INT PRIMARY KEY AUTO_INCREMENT,
          date_time TIMESTAMP,
          reference_code VARCHAR(40), 
          product_id VARCHAR(10))
          Then your (very crude) HL design would look like:
          Code:
          If order is submitted:
          -  obtain product_id of ordered item
          -  generate reference_code
          -  store reference_code, date_time and product_id in table 'references'
          -  create email (with reference_id in link)
          -  send email
          When user places order:
          -  get reference_id from url
          -  read reference_id and product_id from table 'references'
          -  if not valid reference_id: issue error message and exit
          -  if valid reference:
             - prepare product download
             - download product
             - clear entry from table 'references'
          Be aware that this forum is to help you, not to write code for you. You have to do that yourself. So, in case you have to brush-up your programming skills, do so before you go on with this. Good luck!

          Ronald :cool:
          Okay, thanks for the help.

          Just one thing, would the reference_code be a database or a file? And where would the table 'reference' be?

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            I think you have something to learn first about MySQL.

            You do a create of a table (here 'references') after having selected the database
            [php]mysql_select_db ("db_name");[/php]
            reference_code here is neither a database nor a file. It is a column in table 'references' that was created in the example. Into what database this tabe is created depends on the preceeding db selection.

            As I said, you'd better do some tutorials on MySQL before you continue. Some of these are:

            PHP MySQL tutorial
            PHP FOR THE ABSOLUTE BEGINNER

            Ronald :cool:

            Comment

            • jakeruston
              New Member
              • Oct 2006
              • 10

              #7
              I would like to say, that i don't host the server. I bought a web domain with hosting from www.spacialhost ing.com, so how can i use DOS to make databases and such?

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Look at the contract or the guidelines from your server provider. It will say something about usage of the database (its name(s), how to connect, what you are allowed to do and not, etc.) and about using a MySQL administrative user interface such as phpAdmin or the like.

                Ronald :cool:

                Comment

                Working...