View Full Version : calling an FTP script..

03-11-2010, 03:40 PM
Hey everyone,

Im quite new to PHP and learning PHP as i go. To jump in the deep end, im trying to create a PHP FTP page and im stuck at the login screen. I can validate the user but i want is to be able to redirect the user on successful login within the php code. Is this even possible? Ive googled and there are plenty of long winded functions but there must be a quick method.. surely! I cant think of any other way to achieve the redirect, what i really need is to be able to call another php script halfway through the script on my main page..

Any tips are more than welcome!!

03-11-2010, 04:17 PM
As per http://php.net/header:

header("Location: http://www.example.com/");

Note that you can't send headers after outputting; so don't echo any HTML etc. prior to executing that.

03-12-2010, 10:00 AM
Thats one of the things that i had come across initially, but the way im thinking that i would like to go about it, i will need to echo output out first, if that makes sense. I may be going about this the completly wrong way but, i have a page for input that passes to the code below the credentials. What id like is to display a message if the credentials are incorrect otherwise call another script to carry out some other action. This is mainly so that i can have a "logged in page" which obviously the first page wont contain. Hope that makes sense!

$conn = @ftp_connect($ftpServer)
or die("<BR><center><font style='color:#9dacbe'>Couldn't connect to FTP server</font></center>");
$login = @ftp_login($conn, $ftpUser, $ftpPass)
or die("<BR><center><font style='color:#9dacbe'>Login credentials were rejected or incorrect.</font></center>");

$workingDir = ftp_pwd($conn);
// Redirect to go here..
//on successful login redirect to ftp.php so i can list files on FTP server

Am i going about this the wrong way, or is there something ive missed..??