[Help] Creating check-box in website?

Discussion in 'Computer Programming, Emulation, and Game Modding' started by RyDog, May 20, 2016.

  1. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    So I want to create this website that downloads different configs of a NTR plugin, I know how to create checkboxes... but the thing is I want my website to be able to read the input that the user inserts, for example: [​IMG]
    I only want the website to download the custom plugin for Teleport and Speed Hack. (I'll upload all the possible combinations that you can make with this list.)
    Would it be setting those check-boxes a variable like A, B, C and D so that it stores those variables, and download the appropriate file to the variable? (ex: since it's Teleport+SpeedHack It'll set the variable to B+D and download B+D.
    I'm very new to HTML and in my computer science and software engineering class we only went over HTML for a week so my knowledge is still very weak.
    Thanks in advance!
     
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,490
    9,310
    Nov 21, 2005
    Is it basically a list of 15 premade hacks (I assume there is no point in having a blank hack for none of the options selected) then.

    Most people would launch right into a php script ( https://www.formget.com/how-to-redirect-a-url-php-form/ ), maybe javascript, and maybe generate the thing on the fly if they can (though generating binary data with web coding is not the nicest so maybe not). However you could probably code something on the page in javascript to grab the relevant one of 15 files from the server. Javascript is the lesser method but it is also the easier one as it runs on the client's computer and thus your sever merely has to handle HTML and downloading. The checkboxes you mention are part of HTML/web coding known as forms. I am not the greatest fan of w3schools but they do OK here http://www.w3schools.com/html/html_forms.asp

    The crazy way of doing it would be to scratch the checbox approach and do a choose your own adventure style nest of links (page 1 "do you want moon jump, yes, no, just moon jump", page 2 "do you want teleport....) and however many pages you need but I am going to get spat at for suggesting that as a path so I will leave it at that. However if that is all you know and you do not want to tangle with javascript and php it will work just fine. It will be a pick to manage and if you have more than about 4 variables it is going to rapidly increase the time needed to make it (it is going to need "2^(number of variables) -1" pages)..

    Most of the time when doing a checkbox downloader it is for multiple files rather than this (here is one I found on stackexchange a short while ago http://pastebin.com/nZhNzeMa , http://stackoverflow.com/questions/...iple-files-at-the-same-time-having-checkboxes ). However the simple way would be to assign each of those one of the binary values and use it to count to 16, possibly also adding a sanity check in case you do not have anything selected. In case you are not familiar with using binary like this then here is the full list
    0000
    0001
    0010
    0011
    0100
    0101
    0110
    0111
    1000
    1001
    1010
    1011
    1100
    1101
    1111
    I find some people have trouble using this as a logical progression but it really does cover every value. Apologies if I have stated the obvious -- your lack of HTML/web skills could mean your course has not taught you much, or it could just mean that web stuff was not a priority and I have seen it go both ways.

    Assign the first space in the value the moon jump value, second teleport, third duplication, fourth speed hack.
    1000 = just moon jump
    0100 = just teleport
    0010 = duplicaiton
    0001 = speed hack
    You don't have to do it in binary and it will work just as well in hexadecimal (it is still binary underneath it all), however to explain it I left it in binary.
    Anyway so if you add together the values from the checkboxes and get 0011 you know you need duplication and speed and you can download file 3 (0011 = 3 decimal/hex after all). Again like the links this is not a method that scales well but it will work just fine here. If the names of your downloads do not matter (this is for a cheat program so it could go either way) I would just stick it on the download file.

    Afraid I am going to have to leave you at theory at this point rather than workable solution, partially because it is late on Friday evening and partially because I am a bit hazy on javascript myself right now.
     
  3. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    Something like this?

    PHP:
    <?php
    $opts 
    "";

    if (isset(
    $_POST["moonjump"]))
        
    $opts .= "_moonjump";

    if (isset(
    $_POST["teleport"]))
        
    $opts .= "_teleport";

    /* more ifs */

    if ($opts == "")
        die(
    "nope");

    header("Location: /path/to/downloads/ntr" $opts ".whatever");
    ?>
     
    Last edited by 0x40, May 21, 2016
  4. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    Wow is this complicated :wacko:, and I think I'm going to use binary variables like what @FAST6191 told me. And @!() I barely know the basics of HTML/PHP, could you please add comments in your code to elaborate what everything does?
    Thanks for your help so far guys.
     
  5. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    PHP:
    <?php
    $opts 
    ""/* variable that will later contain all the checkbox options */

    if (isset($_POST["moonjump"])) /* condition that checks if a checkbox was checked in the HTML form. */
        
    $opts .= "_moonjump"/* this appends the option to the option string */

    if (isset($_POST["teleport"])) /* we do the same thing for every other option */
        
    $opts .= "_teleport";

    /* you can add as many options as you want like this */

    if ($opts == "")
        die(
    "nope"); /* error handling if user didn't select any options at all */

    header("Location: /path/to/downloads/ntr" $opts ".whatever"); /* redirects user, using options string as part of a file path */
    ?>
     
    RyDog likes this.
  6. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    Ok so what should I do with the HTML so that it uses the PHP for the checkboxes?

    — Posts automatically merged - Please don't double post! —

    This is what I'm using for my HTML right now:
    HTML:
    <!DOCTYPE html>
    <html>
    <body>
    
      <input type="checkbox" name="cheat" value="0001"> Moon Jump <br>
      <input type="checkbox" name="cheat" value="0011"> Teleport <br>
      <input type="checkbox" name="cheat" value="0111"> Duplication <br>
      <input type="checkbox" name="cheat" value="1111"> Speed Hack <br>
      <input type="submit" value="Submit">
    </form>
    
    </body>
    </html>
    
     
  7. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    Put checkboxes in a form element with method="POST" and action="/path/to/phpscript.php", and make sure checkboxes have name corresponding to that in the PHP script (the $_POST[""] part in the ifs.) You don't need the value attributes.
     
    Last edited by 0x40, May 21, 2016
  8. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    So far my HTML is:
    HTML:
    <!DOCTYPE html>
    <html>
    <body>
    <form action="c" method="POST">
      <input type="checkbox" name="moonjump" value="0001"> Moon Jump <br>
      <input type="checkbox" name="teleport" value="0011"> Teleport <br>
      <input type="checkbox" name="dupe" value="0111"> Duplication <br>
      <input type="checkbox" name="speed" value="1111"> Speed Hack <br>
      <input type="submit" value="Submit">
    </form>
    
    </body>
    </html>
    
    PHP is:
    Code:
    <?php
    $opts = ""; /* variable that will later contain all the checkbox options */
    
    if (isset($_POST["moonjump"])) /* condition that checks if a checkbox was checked in the HTML form. */
        $opts .= "_moonjump"; /* this appends the option to the option string */
    
    if (isset($_POST["teleport"])) /* we do the same thing for every other option */
        $opts .= "_teleport";
    
    /* you can add as many options as you want like this */
    
    if ($opts == "")
        die("nope"); /* error handling if user didn't select any options at all */
    
    header("Location: /downloads/cheat.plg" . $opts . ".whatever"); /* redirects user, using options string as part of a file path */
    ?>
    and when I select any of the cheats and click submit it tries directing me to a /c directory?
    [​IMG]
     
  9. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    The action attribute is where it directs you when you click submit. Change it to where the PHP script is.
     
  10. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    whoops, thought I meant to paste and accidentally must've pressed c, good find ;)
    I think I finally get how the php you provided functions now. One last question, can I change the underscores from this "The requested URL /downloads/_moonjump_teleport.whatever was not found on this server." to '/' so I can organize the database?
     
  11. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    You could, but you'd end up with a lot of folders that way. It's simpler just to organize them by file name and have them all in a single folder.
     
  12. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    That's kinda how I want it because with NTR plugins, it uses cheat.plg, so I can't put all of these files in the same directory.
     
  13. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    You could do something like
    PHP:
    header("Location: /downloads/cheat" $opts "/cheat.plg");
    and have a directory for every file.
     
  14. RyDog
    OP

    RyDog Lazy Animal Crossing hacker

    Member
    1,603
    1,181
    Apr 26, 2015
    United States
    Ok currently I'm using a Amazon server that was provided for a lesson we did in my computer science class, so when I use this code:
    PHP:
    header("Location: /downloads/" $opts "cheat.plg"); /* redirects user, using options string as part of a file path */
    it tries going to the root of the server:
    [​IMG]
    and using
    Code:
    header("Location: ~mazzn6gd/downloads/" . $opts . "cheat.plg"); /* redirects user, using options string as part of a file path */
    directs me to:
    [​IMG]
    which is not where I want it to go to. I want it to go to http://cse-www.pltw.org/~mazzn6gd/downloads/moonjump/cheat.plg

    — Posts automatically merged - Please don't double post! —

    I'm moving this server once I figure everything out, but for now I'm using that server as a test
     
  15. 0x40

    0x40 GBAtemp Regular

    Member
    226
    63
    Apr 20, 2013
    If the PHP script is in /~mazzn6gd, you can use Location: downloads/ without the / at the beginning and it will use the directory relative to where the script is.