Jump to content


Photo

FTP Login?


  • Please log in to reply
12 replies to this topic

#1 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 June 2006 - 02:30 AM

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.

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 22 June 2006 - 02:45 AM

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]

#3 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 June 2006 - 02:06 PM

[!--quoteo(post=386709:date=Jun 21 2006, 09:45 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 21 2006, 09:45 PM) View Post[/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.

#4 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 23 June 2006 - 12:51 AM

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.

#5 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 June 2006 - 01:03 AM

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.

#6 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 23 June 2006 - 02:31 AM

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?

#7 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 23 June 2006 - 02:39 AM

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.

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


#8 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 June 2006 - 08:19 PM

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.

<?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);
?>


#9 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 29 June 2006 - 08:36 PM

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.

#10 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 June 2006 - 09:05 PM

[!--quoteo(post=389434:date=Jun 29 2006, 03:36 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 29 2006, 03:36 PM) View Post[/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 :(

#11 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 29 June 2006 - 09:11 PM

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.

#12 SnaD

SnaD
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 29 June 2006 - 09:35 PM

[!--quoteo(post=389457:date=Jun 29 2006, 04:11 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Jun 29 2006, 04:11 PM) View Post[/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"

#13 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 29 June 2006 - 09:47 PM

I'm not a die() expert, however I believe it echo's whatever you put in the quotes, and stops processing the document.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users