Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 48

Thread: More than one input to a form question - how to process?

  1. #31
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    lol, well the 3rd edit killed it!! Outputs all on 1 line again now!! Also, no passwords output at all!!!

    Didn't realise you wern't able to test this out. No worries if you want to look at it later.

    I Appreciate the time you have spent on this one anyway.

  2. #32
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    It's no problem at all. My college finals are over, and this is kinda fun (I know, my life is sad). But yeah, I'll look at it tonight if that's okay. Good luck! Maybe you can fix it before me. If yuo can't, I think I had that problem with a script I wrote a while back and I might be able to dig up my solution if I need to-- it's at home of course

    EDIT: BTW did this work:
    PHP Code:
    echo "Name: ".preg_replace("/\n/","",$names[$i])." Password: ".preg_replace("/\n/","",$passwords[$i]); 
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #33
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    lol, hey, people can say what they want!! I been doing this for around a year now. Still a noob I know!! But I'm learning, and enjoying what I'm getting out of it. But this is why I don't post the real scripts so that I can learn by using examples like this. The actual script itself will be used to auto write a .htaccess file and a .htpasswd file for a user upon request.

    Anyway, no worries, I'll keep knocking my head on the desk in the hope I might spot the problem!! I'm not well experienced though with any of the preg commands. But we'll see what happens.

    Thanks again.

    Smithster.

  4. #34
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    This code worked for me. Produced
    Joey:joey101
    Bobby:bobby99
    Mike:mikes-the-man
    Here it is:
    PHP Code:
    <?php

    if(isset($_POST['submit'])){

       if(@
    preg_match("/\r/",$_POST['names'])){
          
    $names preg_split("/\r/",$_POST['names']);
          
    $passwords preg_split("/\r/",$_POST['passwords']);
       }else if(@
    preg_match("/\n/",$_POST['names'])){
          
    $names preg_split("/\n/",$_POST['names']);
          
    $passwords preg_split("/\n/",$_POST['passwords']);
       }

       for(
    $i=0$i<count($names) || $i<count($passwords);$i++){
          echo 
    ''.preg_replace('/[\r\n]/','',$names[$i]).':'.preg_replace('/[\r\n]/','',$passwords[$i]).'<br>';
       }

    }else{
       echo 
    '<form method = "POST" action = "">';
       echo 
    '<p>Names</p>';
       echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
       echo 
    '<p>Passwords</p>';
       echo 
    '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
       echo 
    '<p><input type="submit" value="Submit" name="submit"></p>';
       echo 
    '</form>';
    }
    ?>
    Last edited by Jas; 12-15-2007 at 04:40 AM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  5. #35
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Sorry for long reply. Been at work all day. Thanks for building this up for me. Works very well. Except for 1 thing!! If a user only puts in 1 username and password, the output is only the first letter of each word.

    e.g.

    output is
    e:s

    Also, next part I am trying to do is encode the password.
    PHP Code:
    $passwd crypt($passwordsbase64_encode($passwords)); 
    That's the command used to encode passwords suitable for .htaccess. I tried to put it into the script but it's throwing errors out at me.

    Any ideas on both of the above?

    Thanks again for all your help with this.

    Smithster.

  6. #36
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Here is the fix to the old script:
    PHP Code:
    <?php 

    if(isset($_POST['submit'])){ 

    $names = array();
    $passwords = array();

       if(@
    preg_match("/\r/",$_POST['names'])){ 
          
    $names preg_split("/\r/",$_POST['names']); 
          
    $passwords preg_split("/\r/",$_POST['passwords']); 
       }else if(@
    preg_match("/\n/",$_POST['names'])){ 
          
    $names preg_split("/\n/",$_POST['names']); 
          
    $passwords preg_split("/\n/",$_POST['passwords']); 
       }else{
          
    $names[] = $_POST['names'];
          
    $passwords[] = $_POST['passwords'];
       }

       for(
    $i=0$i<count($names) || $i<count($passwords);$i++){ 
          echo 
    ''.preg_replace('/[\r\n]/','',$names[$i]).':'.preg_replace('/[\r\n]/','',$passwords[$i]).'<br>'
       }

    }else{ 
       echo 
    '<form method = "POST" action = "">'
       echo 
    '<p>Names</p>'
       echo 
    '<p><textarea rows="10" name="names" cols="37"></textarea></p>'
       echo 
    '<p>Passwords</p>'
       echo 
    '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>'
       echo 
    '<p><input type="submit" value="Submit" name="submit"></p>'
       echo 
    '</form>'

    ?>
    The problem was that it thought, since there were no breaks, that the string was an array. So, char 1 was element 1. Interesting error, and a good catch by you.
    I'll get the crypt in a moment.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. #37
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Nice one Jas, really does work well now

    Thanks again.

  8. #38
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    That's why I got an "A" in my programing class , lol. Here is what you might do for encryption:
    PHP Code:
    for($i=0$i<count($names) || $i<count($passwords);$i++){  
          echo 
    ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),CRYPT_EXT_DES).'<br>';  
       } 
    Let me know if that works. Now, you should not only use that. You should also get creative and encrypt it in other ways-- no one should know how your process of encryption works. One thing you can do in use preg_replace() to replace letters, and then do the crypt function again.

    Also, how are you going to unencrypt it if your using htaccess?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  9. #39
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Nice one, really wish they taught it at my school. But they didn't. Left college not knowing anything about html let alone PHP. Have had to learn it all by myself really. And with the help of forums too. Used to leach scripts off others but then decided it wasn't nice and I should try to create my own!!

    Your coding there almost worked but had to change the encription method to mine.

    .htaccess files apparently use one type of encription. So I've heard. I don't understand much of the wording of the .htaccess file. Just know what it does!! The script I'm writing, maybe I'll pm it to you just so you can see what you have helped me to achieve!!

    I believe I now have enough information to get this script completed.

    Thanks again for all your help. You've been the most helpful with this, and I've asked this on 2 forums!! This one was second. But I haven't had any answer on the other forum!!

    Smithster.

    Edit.....

    Well I seem to have hit another milestone!!!
    The part in this script where it echoes out, I generally echo out first as a test to make sure I get the right result. In order to write the output to a file, I have to create a variable to store it in. If I do this....

    PHP Code:
    for($i=0$i<count($names) || $i<count($passwords);$i++){ 
    //echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
    $content ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
    echo 
    $content;
    $file fopen("/home/psmith83/public_html/test/test.htpasswd""w");

    fwrite($file'' $content '');

    fclose($file);

    $content is output on screen in the correct way. But the file that's created does not look right. Even though I'm telling it to output $content on screen, and then write it to a file. Strange in my eyes, but maybe an error on my part! In the file, it's only writing the last username and password. Also, it's putting <br> at the end of it too!!

    Anything you can see wrong with this?

    Once again, really appreciating your help on this, I just didn't expect to be facing this problem!!

    Thanks

    Smithster.
    Last edited by smithster; 12-15-2007 at 11:37 PM.

  10. #40
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    EDIT Sorry, misread the code.

    The reason it won't work is because it keeps overwriting the file.
    Put the fwrite outside of the loop, and concat the data in the $content var, like so:

    PHP Code:
    for($i=0$i<count($names) || $i<count($passwords);$i++){  
    //echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>'; 
    $content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>'
    }
    echo 
    $content
    $file fopen("/home/psmith83/public_html/test/test.htpasswd""w"); 
    fwrite($file'' $content ''); 
    fclose($file); 
    This way it does it all at once. I asume you know what the concat ('.') does, but incase you don't:
    PHP Code:
    $var 1;
    $var=2;
    echo 
    $var;//outputs 2
    $var .= 1//concat 1-- makes value 21
    echo $var//outputs 21 
    As far as the class, it wan't that great. I am a self taught programer too, as are many on DD as far as I know.

    EDIT2: Note: you can also append the info in the file fopen('file','a') (a instead of w) but doing it after is better in this case--or so I think.
    Last edited by Jas; 12-16-2007 at 01:05 AM.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •