Jump to content

liberate

Members
  • Posts

    44
  • Joined

  • Last visited

Posts posted by liberate

  1. Just posting an update.

     

    Limiting to only five selected was easy to find. There is a fiddle of it  http://jsfiddle.net/jaredhoyt/Ghtbu/1/  The code is above in previous post.

     

    Decided to do the rest in php.

     

    After a little googling, the answer to the array and mapping only those selected to the five set names was very easy.  The code below does the job. This  is form_pro.php in the post above.

    $selected = $_POST['selected'];
    
    array_filter($selected);
     
    
    $test0 = $selected[0];
    $test1 = $selected[1];
    $test2 = $selected[2];
    $test3 = $selected[3];
    $test4 = $selected[4];
    
    

    Next I just have to retrieve the email addresses from mysql based off of each person's unique identifier. That's easy.

  2. I think I am getting closer... But not there yet.

    <!DOCTYPE html>
    <head>
    <!-- Include jQuery! -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    
    <script>
    jQuery(function(){
        
    var max = 5;
        
    var checkboxes = $('input[type="checkbox"]');
                           
        
    checkboxes.change(function(){
            
    var current = checkboxes.filter(':checked').length;
            
    checkboxes.filter(':not(:checked)').prop('disabled', current >= max);
       
      });
    });
    </script>
    </head>
    <body>
    
    <form method="post" action="http://mysite.com/form_pro.php">
    <input type="checkbox" name='selected[]' value="unique1" />John Doe<br>
    <input type="checkbox" name='selected[]' value="unique2" />Jane Doe<br>
    <input type="checkbox" name='selected[]' value="unique3" />John Doe<br>
    <input type="checkbox" name='selected[]' value="unique4" />Bill Doe<br>
    <input type="checkbox" name='selected[]' value="unique5" />Billy Bob<br>
    <input type="checkbox" name='selected[]' value="unique6" />etc<br>
    <input type="checkbox" name='selected[]' value="unique7" />etc<br>
    <input type="checkbox" name='selected[]' value="unique8" />etc<br>
    <input type="checkbox" name='selected[]' value="unique9" />etc<br>
    etc. // no need to include all code yet.
    <input type="submit" value="Submit">
    </form>
    
    
    
    
    // Not sure how to get the array to work. 
    // I found this but don't know how it works or if it actually does what I want it to do.
    
    <script type="text/javascript">
    var selected = new Array();
    $(document).ready(function() {
      $("input:checkbox[name=type]:checked").each(function() {
           selected.push($(this).val());
      });
    });
    </script>
    

    I suppose that as long as I am only submitting the 5 selected checkboxes, I can do the mapping to the 5 set names in php. Although I don't know how to that either.

     

    Any help or assistance would be greatly appreciated.

  3. Hi dalecosp

     

    The method I have used in the past to slow down spam bots is:

    <script language="JavaScript" type="text/javascript">
    <!--
    var name = "john";
    var domain = "doe.com";
    document.write('<a class=\"footer\" href=\"mailto:' + name + '@' + domain + '\">');
    document.write(name + '@' + domain + '<\/a>');
    // -->
    </script>
    

    I know some new methods use captcha, which I will not be able to do for this application.

     

    I understand the sanity question, and in fact the list of optional checkbox could grow to 50 or so over time, at which time I will agree with you on the insanity of the situation, however I can't see any other option.  With that in mind I can't see submitting 50 inputs, only 5 having values and let php find the five with values. Client side would seam to be the way to go. 

     

    One addition to the set up: I would like one of the options to be a user filled text field, so that if the user can't find the option they want among the 20 ("cough" - or 50) they can add the one they want.

     

    With the spam bot question, I could have 50 good (primary) email addresses sitting in html on a webpage, that I need to ensure don't get harvested. It would be much more secure to just have the names in html and let php retrieve the emails of the selected names from mysql during form processing. OK so I am going with adding the emails in php during processing.

     

    With client side option, what code do I need to find the five selected options and assign them to the five input names? I have never worked with arrays or loops.

  4. Hi Everyone
    
    I want to have 5 form inputs with 5 standardized names, but I want the 
    values to come from 20 or more checkbox options.
    
     // using slashes as comments
     
    <input type="hidden" name="input1" value= "// value of checkbox \\ > 
    <input type="hidden" name="input2" value= "// value of checkbox \\ > 
    <input type="hidden" name="input3" value= "// value of checkbox \\ > 
    <input type="hidden" name="input4" value= "// value of checkbox \\ > 
    <input type="hidden" name="input5" value= "// value of checkbox \\ > 
    
    
    
    // limiting that the 6th checkbox doesn't become checked without first 
    deselecting another.
    
    <input type="checkbox" name="input[]" value= " john@doe.com ">
    <input type="checkbox" name="input[]" value= " jane@doe.com "> // and 20 or 
    more checkboxes
    etc.
    etc.
    etc.
    etc.
    etc.
    So upto 5 selected checkboxes become the name="input1" through 
    name="input5".
    
    Or I could have 20 checkboxes with 20 names, any 5 of which being 
    submitted in the form. But then (Server Side) I would have to map (for 
    lack of a better term) 5 unknown form names to 5 set variables
    <?php
    $input1 = $_POST[" // first input from form \\ "];  
    $input2 = $_POST[" // second input from form \\ "]; 
    $input3 = $_POST[" // third input from form \\ "]; 
    $input4 = $_POST[" // fourth input from form \\ "]; 
    $input5 = $_POST[" // fifth input from form \\ "];
    

    Over time the number of checkbox options will increase, and I will have to update the html form, but it would be nice if the code didn't have to change as the number of options increases.

     

    I have to make 20+ options, upto 5 of which get selected, matched to 5 standardized named inputs, but not sure which is easier: client side or server side?

     

    And since the form values are email addresses, I will have to keep the spam bots from harvesting them. I have an old method, what are the current solutions?

     

    Thanks in advance

    Tom

     

    Grrr. I have everything laid out all organized, looking just as I want and then hit submit and all he** breaks loose.

  5. Hi Andy-H

     

    Tried to build on what you wrote. Here is what I used.

    <?php 
    
    $host = $_SERVER["HTTP_HOST"]; 
    var_dump(str_replace(array('www.', '.mysite1234.com'), '', ($host)));
    
    $username = $host;
    

    returned:

    string(14) "12.er-3x.5g-3v"

     

    So it correctly found the crazy username I am using as a test. But I assume a little more code is needed.

     

    Tom

  6. How the he** did the code jump out of their code wrapper (for lack of a better term) as soon as I went to post this. It all looked fine until I hit post. Frustrating or what? and edit didn't fix it they jumped out again.

  7. Thanks to requinix  jazzman1  and kicken

     

    I now have 3 solutions to the problem of how to retrieve the value of a subdomain ie. username, when that username can have dot or dash punctuation.

    
    

    jazzman1:

     

    <?php // get host name from URL $host = $_SERVER['HTTP_HOST']; preg_match('/^((\bhttps?:\/\/(www.)?|\bwww\.)?([a-z.-\d]+)?\.)?([a-z\d]+\.[a-z]{2,4}\/?)$/i', $host, $matches); $username = $matches[4];

    
    

    kicken:

     

    <?php $host = explode('.', $_SERVER["HTTP_HOST"]); if ($host[0] == 'www') array_shift($host); //Remove the base domain. This assumes your base domain contains only one dot (example.com) rather than two (example.co.uk) $host = array_slice($host, 0, -2); $username = implode('.', $host);

    
    

    requinix:

     

    <?php $host = $_SERVER["HTTP_HOST"]; if (strncmp($host, "www.", 4) == 0) { $host = substr($host, 4); } if (substr_compare($host, ".mysite1234.com", -15 /* -strlen(".mysite1234.com") */) == 0) { $host = substr($host, 0, -15); } $username = $host;

     

     

    All as far as I can tell they all generating the same results.

     

    So if I wanted to really "stir the pot", I would ask which one is better?

     

    Thnaks again

    Tom

     

    Background info for anyone just landing here:

    I have wildcard subdomain redirected to root. Works without needing any htaccess. The subdomain is just a placeholder for username. Then I use php to pull out the username (subdomain) and retrieve their saved info from mysql. It is a multi-user self-reolicated site. usernames are alpha-numeric with dot and dash allowed. Personal web addresses are in http://username,mydomain.com format, and the backbone of the site is an autoresponder program.

  8. Hi  requinix

     

    I just tried:

    <?php 
    
    
    $host = $_SERVER["HTTP_HOST"]; 
    if (strncmp($host, "www.", 4) == 0) {
        $host = substr($host, 4);
    }
    if (substr_compare($host, ".mysite1234.com", -15 /* -strlen(".mysite1234.com") */) == 0) {
        $host = substr($host, 0, -15);
    }
    
    echo $host;
    
    

    echo returned:

    the username 12.er-3x.5g-3v  correctly,  so at this stage working.

     

    now make it

    $username = $host;

    and working !!!

     

    Thanks requinix  That's 3 working solutions to one problem

  9. Hi Kicken

     

    Your right it works.. This was the tweak to my original code that I was looking for.

    $host = explode('.', $_SERVER["HTTP_HOST"]);
    if ($host[0] == 'www') array_shift($host);
    //Remove the base domain.  This assumes your base domain contains only one dot (example.com) rather than two (example.co.uk)
    $host = array_slice($host, 0, -2);
    $username = implode('.', $host);
    

    Just tried your code below 

    <?php 
    
    $host = $_SERVER["HTTP_HOST"]; 
    if (strncmp($host, "www.", 4) == 0) {
        $host = substr($host, 4);
    }
    $baseDomain = '.mysite1234.com';
    $baseLen = strlen($baseDomain);
    if (substr_compare($host, $baseDomain, -$baseLen) == 0) {
        $host = substr($host, 0, -$baseLen);
    }
    
    $username = $host // added this but it isn't right (500 internal server error)
    

    Can't figure out what to make $username=

     

    Thanks Tom

  10. Hi kicken

     

    re: $host = explode('.', $_SERVER["HTTP_HOST"]);

     

    And that works when usernames contain dot (.)?  My original my_admin.php failed when usernames contained a dot. That is what started this exercise.

     

    Tom

  11. Hi Jazz

     

    Your code worked once I changed to $host = "http://" . $_SERVER['HTTP_HOST'];

    <?php
        // get host name from URL   
     
     $host = "http://" . $_SERVER['HTTP_HOST'];
       
     preg_match('/^((\bhttps?:\/\/(www.)?|\bwww\.)?([a-z.-\d]+)?\.)?([a-z\d]+\.[a-z]{2,4}\/?)$/i', $host, matches);
               
     echo '<pre>'.print_r($matches, true).'</pre>';
    
    

    echo returned:

    Array
    (
        [0] => http://www.us.er-na.me-s-er.mysite1234.com
        [1] => http://www.us.er-na.me-s-er.
        [2] => http://www.
        [3] => www.
        [4] => us.er-na.me-s-er
        [5] => mysite1234.com)

     

    Hurray

     

    (was getting tired of  :facewall:  beating my head against a brick wall)

     

    So now I should just need to make $user = $matches[4];

     

    Hurray!!  $user = $matches[4]; worked. And I see my username and my info retrieved from mysql.

     

    I just registered a new fictitious new member with the username 12.er-3x.5g-3v and it worked.. Retrieved corresponding info from mysql.

     

    So here's my new my_admin.php, thanks of course to jazzman1 !!

    <?php 
    
    
        // get host name from URL
        $host = "http://" . $_SERVER['HTTP_HOST'];
         
        preg_match('/^((\bhttps?:\/\/(www.)?|\bwww\.)?([a-z.-\d]+)?\.)?([a-z\d]+\.[a-z]{2,4}\/?)$/i', $host, $matches);
         
        $user = $matches[4];
    
    

    Not sure why you think php isn't suited. It works.

     

     

     

    To complete this story I would still like to know what it would take for requinix method to work.

     

     

    Thanks Tom

  12. Hi Jazz

    I didn't mean I was giving up on your method. requinix showed up after you went to bed. I had not spent anytime on requinix method. Initially I didn't get anywhere with it but i soon realized that the numbers were digits of offset, and I needed to more closely represent the length of my domain.

     

    So far neither method has worked.

     

    The one main question I have with your approach is how are you retrieving the visitor's username without $host = $_SERVER["HTTP_HOST"]; ?

     

    If you need http:// then build it with $host = "http://" . $_SERVER['HTTP_HOST'], so that $host holds a variable that changes with every visitor's username. I can't see how a static host=http://www.username.mysite1234.com can work in a dynamic self-replicated multi-user website.

     

    I am either missing something here or we are taking about two different uses.

     

    I know you like the RegEx method because it will work with any domain, so anyone else can use the same code, without having to alter it to suit them.

     

    Like most sites usernames are alpha-numeric with allowed punctuation of dot and dash (.-) In my case underscore is not allowed (_)

     

    I appreciate your help.

     

    Tom

  13. Legthened the domain name to correctly represent real condition.

    <?php 
    
    $host = $_SERVER["HTTP_HOST"]; 
    if (strncmp($host, "www.", 4) == 0) {
        $host = substr($host, 4);
    }
    if (substr_compare($host, ".mysite1234.com", -15 /* -strlen(".mysite1234.com") */) == 0) {
        $host = substr($host, -15);
    }
    
    // $user = $host
    echo $host;
    

    echo returned:

    .mysite1234.com

     

    So this returned the domain instead of the subdomain.

     

    So what has to be altered to get the subdomain?

  14. Going back to @requinix script

     

     

    I put this into the top of my_admin.php

    <?php 
    
    $host = $_SERVER["HTTP_HOST"]; i
    if (strncmp($host, "www.", 4) == 0) {
        $host = substr($host, 4);
    }
    if (substr_compare($host, ".mysite.com", -11 /* -strlen(".mysite.com") */) == 0) {
        $host = substr($host, -11);
    }
    
    echo $host;
    

    Echo returned:

    liberate.mysite.com

     

    So $host is not subdomain but contains both sub and domain, and yes I did alter the "mysite.com" in the code to the real domain.com.

     

    Something not quite right.

  15. Good night jazzman1 :sleeping:

     

    So $host has to be a known variable? Then I don't see how this can work. Username changes each time a different member comes to the site.

     

    My username might be liberate, but what about the other users? $host = "http://www.liberate.mysite.com/";  would program the site only to work for me.

     

    Am I missing something here?

     

    Tom

  16. I put this into the top of my_admin.php

    <?php 
    
    $host = $_SERVER["HTTP_HOST"];
    
    preg_match('/^((\bhttps?:\/\/(www.)?|\bwww\.)?([a-z.-]+)?\.)?([a-z]+\.[a-z]{2,4}\/?)$/i', $host, $matches);
    
    // $user = $matches[4];
    
    echo '<pre>'.print_r($matches, true).'</pre>';
    

    echo returned empty

    Array()

    I assume I am doing something wrong.

  17. Hi jazzman1

     

    You're up late. I live about 1 1/2 hours from you.

     

    So in my admin.php I would do.

    <?php 
    
    $host = $_SERVER["HTTP_HOST"];
    
    preg_match('/^((\bhttps?:\/\/(www.)?|\bwww\.)?([a-z.-]+)?\.)?([a-z]+\.[a-z]{2,4}\/?)$/i', $host, $matches);
    
    $user = $matches[4];
    

    And then look up $user in mysql.

     

    I will give it a try.

     

    Thanks

    Tom

    my email liberate at uc2 dot biz (old address that gets lots of spam) email me. 

  18. How would you use $host = http://www.any-user.name.mysite.com; ?

     

     

    For lack of the technical way of saying it.....The script needs to retrieve the url from the address bar.

     

    When a registered member comes to mysite.com they use their personal url http://www.their-username.mysite.com or http://their-username.mysite.com or http://theirusername.mysite.com

     

    It is a multi-user self-replicating site. The admin.php file then retrieves the username from the "address bar"  and looks up the rest of their info from mysql.

  19. Hi jazzman1

     

    I don't underestimate the power of RegEx just don't understand it.

     

     

    So array [4] is always the username?

     

     

    Does this work?

    <?php 
    
    $host = "$_SERVER["HTTP_HOST"]";
    preg_match('/((\bhttps?:\/\/(www.)?|\bwww\.)([a-z.-]+)?\.([a-z]+\.[a-z]{2,4}(\/)?)$)/i', $host, $matches);
    
    $user = $matches[4];
    

    Thanks Tom

  20. Thank you requinix  and  jazzman1

     

    As long as requinix solution works with usernames that contain dots or dashes, simple is always better to me.

     

    http://www.any.user-name.mysite.com username = any.user-name

     

    http://any.user-name.mysite.com username = any.user-name  (with or without www)

     

    I have been reading for hours goggle searches on ``preg_match() subdomain url`` and not geting anywhere, except very confused.

     

    requinix so at the end of your script does $host = username

     

     

    Since I am not scanning random urls, RegEX did seem like overkill. In the past few hours I have read more RegEX expressions then I care to count, not that I understood any of them.

     

    Thanks again

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.