Web Analytics Made Easy -
StatCounter PHP for Browser-Based FTP login - CodingForum


No announcement yet.

PHP for Browser-Based FTP login

  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP for Browser-Based FTP login

    I simply want to allow users access FTP access through a browser.

    However, I'm using a hosting company with cPanel and in order to set up an FTP account that only gives access to a specific subfolder on my account, a username is generated with an "@" in it. (ex. [email protected]).

    This makes it impossible for to just enter the info into the address bar (in the form of ftp://[email protected]@www.mydomain.com) because once the browser sees that first "@" sign, everything goes to heck...

    I've tried to just get the browser to prompt the user for the login info - which it does just fine everywhere I've tried it - but my client's computer is not doing it. I don't like telling clients to change setting on their machines, or install software (like FTP clients), because then I become tech support instead of just a web developer. I don't like the associated liability...

    Sooo - what I want to be able to do to solve all these problems is create a simple form that collects the server, username, and password; processes the info with PHP; BUT THEN just directs them into their FTP folder via the browser.

    What I'm finding is that everyone who has developed a PHP FTP login script has also developed some convoluted interface to go with it and they're either way too complicated for my needs, or they simply don't work.

    All I want to be able to do is allow users to input their username - with an "@" in it - and password, and then see the same thing that someone would see using the simple ftp://user[email protected] method.

    I'm going nuts. Can it even be done?
    Last edited by jakerbug; Sep 24, 2006, 03:45 PM.

  • #2
    The HTML form:
    <form method="post" action="ftplogin.php">
    Server: <input type="text" name="server">
    Username: <input type="text" name="username">
    Password: <input type="password" name="password">
    <input type="submit" value="submit">
    The ftplogin.php page
    PHP Code:
    $server $_POST['server'];
    $password $_POST['password'];
    $location "ftp://$username@$server:$password@www.$server";
    header("Location: $location");
    Web Programming Tutorial
    Python Web Programming Tutorial
    Programming Tutorial for absolute beginners


    • #3
      that's returning a "cannot find server" error page.

      any ideas?


      • #4
        it looks like this method is just passing the "[email protected][email protected]" thing to the browser using PHP. Essentially, it runs into the same problem as just typing that into the address bar...


        • #5
          If that is the case then try to urlencode():
          PHP Code:
          $location "ftp://" urlencode("$username@$server") . ":$password@www.$server"
          Web Programming Tutorial
          Python Web Programming Tutorial
          Programming Tutorial for absolute beginners


          • #6
            works like a charm! thanks a lot.