Jump to content

Archived

This topic is now archived and is closed to further replies.

SnaD

FTP Login?

Recommended Posts

Hey guys. I really need a php script that would ask user for ftp login and pass. If they are correct, script would get user to specific ftp; otherwise, error. Anyone? Thanks in advance.

Share this post


Link to post
Share on other sites
tried the sample code on php.net yet?

[a href=\"http://us2.php.net/manual/en/function.ftp-login.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.ftp-login.php[/a]

Share this post


Link to post
Share on other sites
[!--quoteo(post=386709:date=Jun 21 2006, 09:45 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 21 2006, 09:45 PM) [snapback]386709[/snapback][/div][div class=\'quotemain\'][!--quotec--]
tried the sample code on php.net yet?

[a href=\"http://us2.php.net/manual/en/function.ftp-login.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.ftp-login.php[/a]
[/quote]

Thanks, im gonna try it now.

Share this post


Link to post
Share on other sites
It did work but not exactly how I wanted it to. It just outputs "Connected as user@server.com," whereas I want it to redirect user to ftp server. Anyone? Appreciate it.

Share this post


Link to post
Share on other sites
To simply redirect the browser to a ftp site that requires a login and password, you just have to know the language. Once you've got that, you can create a hyperlink, do a header redirect, or any number of things. Here's the language:

[a href=\"ftp://user:password@ftp.example.com\" target=\"_blank\"]ftp://user:password@ftp.example.com[/a]

I believe most browser supports this. Challenge, of course, is you're sending the username and password in plain text across the internet. But, come to think of it, standard FTP does the same thing.

Share this post


Link to post
Share on other sites
Here is a part of my code:

<?php
if(isset($_POST['submit'])) {
header("Location:ftp://".$_GET['log'].":".$_GET['pass']."@server.com");
exit;
} else {
?>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="titleblue">
Username&nbsp;
</td>
<td>
<input name="log" type="text" style="color:013B84;font-weight:bold;background-color:transparent;border-color:013B84;border-width:1;border-style:solid">
</td>
</tr>
<tr>
<td class="titleblue">
Password&nbsp;
</td>
<td>
<input name="pass" type="password" style="cime-mode:active;color:013B84;font-weight:bold;background-color:transparent;border-color:013B84;border-width:1;border-style:solid">
</td>
</tr>
<tr>
<td width="10">&nbsp;
</td>
<td align="center">
<input type="submit" name="submit" value="Login" style="cursor:hand;font-weight:bold;color:000099;background-color:white;border-color:013B84;border-width:1;border-style:solid">
</td>
<td width="30">&nbsp;
</td>
</tr>
</table>
<?php
}
?>

I get this warning:
Warning: Cannot modify header information - headers already sent by (output started at C:\site\NEW\client_access.php:5) in C:\site\NEW\client_access.php on line 85

Any ideas? What am I doing wrong?

Share this post


Link to post
Share on other sites
you either need to buffer output, or not output any information before the header. This is in the FAQ if you have more questions.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95562\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95562[/a]

For testing purposes you could include a javascript code to get you going. It should simulate a header redirect until you get your PHP header problem addressed. You will eventually want to use the PHP method, though, because not all visitors will have javascript turned on.

[code]<script language="javascript">window.location = "http://www.example.com"; </script>[/code]

Share this post


Link to post
Share on other sites
Hey guys,

I have one more problem. Here is my code to ftp.php. Smth strange is happening.
When I submit my form, IE says that my ftp.php not found (404), whereas Firefox connects to ftp, but gives me "426 Connection Closed" error. Anyone knows how to fix this? Thanks.

[code]
<?php
                    
$ftp_server = "mysite.com";
$ftp_user = $_REQUEST['log'];
$ftp_pass = $_REQUEST['pass'];

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
   header("Location: ftp://$ftp_user:$ftp_pass@$ftp_server");
} else {
   include 'error_ftp.htm';
}

// close the connection
ftp_close($conn_id);
?>
[/code]

Share this post


Link to post
Share on other sites
If you have unix, try curling the page

curl -I -dlog=loginname -dpass=password [a href=\"http://www.example.com/ftp.php\" target=\"_blank\"]http://www.example.com/ftp.php[/a]

the uppercase "I" will return the header only, so you can see where it's trying to send you. Copy the address and plug it in your browser.

Share this post


Link to post
Share on other sites
[!--quoteo(post=389434:date=Jun 29 2006, 03:36 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 29 2006, 03:36 PM) [snapback]389434[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you have unix, try curling the page

curl -I -dlog=loginname -dpass=password [a href=\"http://www.example.com/ftp.php\" target=\"_blank\"]http://www.example.com/ftp.php[/a]

the uppercase "I" will return the header only, so you can see where it's trying to send you. Copy the address and plug it in your browser.
[/quote]

No, I don't have unix :(

Share this post


Link to post
Share on other sites
go to [a href=\"http://web-sniffer.net/\" target=\"_blank\"]http://web-sniffer.net/[/a]

put in your url like this:

[a href=\"http://www.example.com/ftp.php?log=username&pass=password\" target=\"_blank\"]http://www.example.com/ftp.php?log=username&pass=password[/a]

select the "POST" radio header

submit.

Share this post


Link to post
Share on other sites
[!--quoteo(post=389457:date=Jun 29 2006, 04:11 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 29 2006, 04:11 PM) [snapback]389457[/snapback][/div][div class=\'quotemain\'][!--quotec--]
go to [a href=\"http://web-sniffer.net/\" target=\"_blank\"]http://web-sniffer.net/[/a]

put in your url like this:

[a href=\"http://www.example.com/ftp.php?log=username&pass=password\" target=\"_blank\"]http://www.example.com/ftp.php?log=username&pass=password[/a]

select the "POST" radio header

submit.
[/quote]

Nevermind, i figured it out. It was because of my stupid server. Anyways, I appreciate ur help.

One more thing [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

die("Couldn't connect to $ftp_server");

Is there a way to insert html page in die() instead of just saying "Couldn't connect to $ftp_server"

Share this post


Link to post
Share on other sites
I'm not a die() expert, however I believe it echo's whatever you put in the quotes, and stops processing the document.

Share this post


Link to post
Share on other sites

×

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.